Skip to content

Commit

Permalink
Reprort about child process errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pyhalov committed Nov 10, 2018
1 parent 5935126 commit 0aa6233
Showing 1 changed file with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- mate-control-center-1.20.3/capplets/about-me/mate-about-me-password.c.~1~ 2018-05-19 15:55:23.000000000 +0000
+++ mate-control-center-1.20.3/capplets/about-me/mate-about-me-password.c 2018-11-10 08:59:36.935195423 +0000
+++ mate-control-center-1.20.3/capplets/about-me/mate-about-me-password.c 2018-11-10 21:18:53.937876433 +0000
@@ -27,6 +27,11 @@
# include <config.h>
#endif
Expand Down Expand Up @@ -29,13 +29,23 @@

#if __sun
#include <sys/types.h>
@@ -170,85 +185,123 @@
@@ -85,6 +100,9 @@
/* Buffer size for backend output */
#define BUFSIZE 64

+/* Bufffer size for backend error messages */
+#define ERRBUFSIZE 1024
+
/*
* Error handling {{
*/
@@ -170,85 +188,156 @@
spawn_passwd (PasswordDialog *pdialog, GError **error)
{
gchar *argv[2];
- gchar *envp[1];
- gint my_stdin, my_stdout, my_stderr;
+ int pid, pty_m;
+ int pid, pty_m, err_pipe[2];
+ char slave_name[PTY_MAX_NAME];
+ char *name;

Expand Down Expand Up @@ -127,14 +137,23 @@
- pdialog->backend_stdout_watch_id = g_io_add_watch (pdialog->backend_stdout,
- G_IO_IN | G_IO_PRI,
- (GIOFunc) io_watch_stdout, pdialog);
+ if (pipe2(err_pipe, O_CLOEXEC) < 0) {
+ fprintf(stderr, "Couldn't create error reporting pipe: %s\n", strerror(errno));
+ close(pty_m);
+ return FALSE;
+ }
+
+ pid = fork();
+ if (pid == 0) {
+ /* Child */
+ int pty_s;
+
+ int pty_s, len;
+ char buf[ERRBUFSIZE];
+ close(err_pipe[0]);
+
+ close(pty_m);
+ if (setsid() < 0) {
+ fprintf(stderr, "Couldn't create new process group: %s\n", strerror(errno));
+ len = snprintf(buf, ERRBUFSIZE, "Couldn't create new process group: %s\n", strerror(errno));
+ write(err_pipe[1], buf, (len>ERRBUFSIZE) ? ERRBUFSIZE : len );
+ return FALSE;
+ }

Expand All @@ -145,16 +164,18 @@

- /* Success! */
+ if (pty_s < 0) {
+ fprintf(stderr, "Couldn't open slave terminal device: %s\n", strerror(errno));
+ len = snprintf(buf, ERRBUFSIZE, "Couldn't open slave terminal device: %s\n", strerror(errno));
+ write(err_pipe[1], buf, (len>ERRBUFSIZE) ? ERRBUFSIZE : len );
+ return FALSE;
+ }
+
+#if defined(TIOCSCTTY) && !defined(__sun)
+ /* BSD systems need to set controlling tty explicitly. Solaris/illumos can export
+ TIOCSCTTY when __EXTENSIONS__ are defined, but doesn't need this. */
+ if (ioctl(pty_s,TIOCSCTTY, NULL) < 0) {
+ fprintf(stderr, "Couldn't establish controlling terminal: %s\n", strerror(errno));
+ close(pty_s);
+ len=snprintf(buf, ERRBUFSIZE, "Couldn't establish controlling terminal: %s\n", strerror(errno));
+ write(err_pipe[1], buf, (len>ERRBUFSIZE) ? ERRBUFSIZE : len );
+ return FALSE;
+ }
+#endif
Expand All @@ -167,12 +188,33 @@
+ execvp(argv[0], argv);
+
+ /* Error */
+ fprintf(stderr, "Couldn't exec passwd: %s\n", strerror(errno));
+ close(pty_s);
+ len=snprintf(buf, ERRBUFSIZE, "Couldn't exec passwd: %s\n", strerror(errno));
+ write(err_pipe[1], buf, (len>ERRBUFSIZE) ? ERRBUFSIZE : len );
+ return FALSE;
+ } else if (pid > 0) {

- return TRUE;
+ int rb, pos = 0;
+ char buf[ERRBUFSIZE];
+
+
+ close(err_pipe[1]);
+ /* Wait for child to run exec() and read possible error message */
+ while (pos < ERRBUFSIZE - 1 && ((rb=read(err_pipe[0], &buf[pos], BUFSIZE-1-pos)) > 0)) {
+ pos += rb;
+ }
+ close(err_pipe[0]);
+ if (pos > 0) {
+ /* There were messages in err_pipe */
+ buf[pos+1] = '\0';
+ g_set_error (error,
+ PASSDLG_ERROR,
+ PASSDLG_ERROR_BACKEND,
+ buf);
+
+ stop_passwd(pdialog);
+ return FALSE;
+ }
+
+ /* Open IO Channels */
+ pdialog->backend_stdin = g_io_channel_unix_new (pty_m);
+ /* g_io_channel_shutdown(pdialog->backend_stdin) will close associated file descriptor (pty_m),
Expand All @@ -192,7 +234,8 @@
+ stop_passwd (pdialog);
+ return FALSE;
+ }
+

- return TRUE;
+ /* Turn off buffering */
+ g_io_channel_set_buffered (pdialog->backend_stdin, FALSE);
+ g_io_channel_set_buffered (pdialog->backend_stdout, FALSE);
Expand All @@ -217,7 +260,7 @@
}

/* Stop passwd backend */
@@ -822,7 +875,7 @@
@@ -822,7 +924,7 @@

/* translators: Unable to launch <program>: <error message> */
details = g_strdup_printf (_("Unable to launch %s: %s"),
Expand Down

0 comments on commit 0aa6233

Please sign in to comment.