diff options
Diffstat (limited to 'daemon/misc.c')
-rw-r--r-- | daemon/misc.c | 279 |
1 files changed, 126 insertions, 153 deletions
diff --git a/daemon/misc.c b/daemon/misc.c index eb1408f0..5b26473a 100644 --- a/daemon/misc.c +++ b/daemon/misc.c @@ -31,259 +31,232 @@ static const gchar RCSid[]="$Id$"; -gchar **gdm_arg_munch(gchar *p); -gint gdm_exec_script(GdmDisplay *d, gchar *dir); -void gdm_exec_command(gchar *cmd); -void gdm_fail(const gchar *format, ...); -void gdm_abort(const gchar *format, ...); -void gdm_info(const gchar *format, ...); -void gdm_error(const gchar *format, ...); -void gdm_debug(const gchar *format, ...); -void gdm_remanage(const gchar *format, ...); -void gdm_putenv(gchar *s); +gchar **gdm_arg_munch (gchar *p); +gint gdm_exec_script (GdmDisplay *d, gchar *dir); +void gdm_fail (const gchar *format, ...); +void gdm_abort (const gchar *format, ...); +void gdm_info (const gchar *format, ...); +void gdm_error (const gchar *format, ...); +void gdm_debug (const gchar *format, ...); +void gdm_remanage (const gchar *format, ...); + extern gchar *GdmPidFile; -extern gchar *GdmDefaultPath; +extern gchar *GdmRootPath; extern gint GdmDebug; +/* Written by Alan Cox <alan@redhat.com> */ gchar ** -gdm_arg_munch(gchar *p) +gdm_arg_munch (gchar *p) { - gchar *x=strdup(p); - gint quoted=0; - gint argn=0; - static gchar *argv[16]; + gchar *x = strdup (p); + gint quoted = 0; + gint argn = 0; + static gchar *argv[16]; + + while (*x) { + while (*x && isspace (*x)) + x++; - while(*x) - { - while(*x && isspace(*x)) - x++; - - if(*x=='"') - { - quoted=1; - x++; - } - - argv[argn]=x; - - while(*x) - { - if(*x=='"' && quoted) - break; - if(*x==' ' && !quoted) - break; - x++; - } - - if(*x) - *x++=0; - argn++; - if(argn==16) - break; + if (*x=='"') { + quoted = 1; + x++; } - - while(argn<=16) { - argv[argn]=NULL; - argn++; - }; - - return argv; + + argv[argn] = x; + + while (*x) { + + if (*x=='"' && quoted) + break; + + if (*x==' ' && !quoted) + break; + + x++; + } + + if (*x) + *x++ = 0; + + argn++; + + if (argn==16) + break; + } + + while (argn<=16) { + argv[argn] = NULL; + argn++; + } + + return (argv); } -/* Execute a script and wait for it to finish */ -gint -gdm_exec_script(GdmDisplay *d, gchar *dir) +/* Execute a script and wait for it to finish. Returns exit status of + * the executed script. + */ +gint +gdm_exec_script (GdmDisplay *d, gchar *dir) { pid_t pid; gchar *script, *defscript, *scr; gchar **argv; gint status; - script = g_strconcat(dir, "/", d->name, NULL); - defscript = g_strconcat(dir, "/Default", NULL); + if (!d || !dir) + return (EXIT_SUCCESS); + + script = g_strconcat (dir, "/", d->name, NULL); + defscript = g_strconcat (dir, "/Default", NULL); - if(!access(script, R_OK|X_OK)) - scr=script; - else if (!access(defscript, R_OK|X_OK)) - scr=defscript; + if (! access (script, R_OK|X_OK)) + scr = script; + else if (! access (defscript, R_OK|X_OK)) + scr = defscript; else - return(EXIT_SUCCESS); + return (EXIT_SUCCESS); - switch(pid=fork()) { + switch (pid = fork()) { case 0: - gdm_putenv(g_strconcat("PATH=", GdmDefaultPath, NULL)); - argv=gdm_arg_munch(scr); - execv(argv[0], argv); - syslog(LOG_ERR, _("gdm_exec_script: Failed starting: %s"), scr); - return(EXIT_SUCCESS); + setenv ("PATH", GdmRootPath, TRUE); + argv = gdm_arg_munch (scr); + execv (argv[0], argv); + syslog (LOG_ERR, _("gdm_exec_script: Failed starting: %s"), scr); + return (EXIT_SUCCESS); case -1: - syslog(LOG_ERR, _("gdm_exec_script: Can't fork script process!")); - return(EXIT_SUCCESS); + syslog (LOG_ERR, _("gdm_exec_script: Can't fork script process!")); + return (EXIT_SUCCESS); default: - waitpid(pid, &status, 0); /* Wait for script to finish */ + waitpid (pid, &status, 0); /* Wait for script to finish */ - if(WIFEXITED(status)) - return(WEXITSTATUS(status)); + if (WIFEXITED (status)) + return (WEXITSTATUS (status)); else - return(EXIT_SUCCESS); - }; -} - - -void -gdm_exec_command(gchar *cmd) -{ - pid_t pid; - gchar **argv; - - if(!cmd) return; - - switch(pid=fork()) { - - case 0: - gdm_putenv(g_strconcat("PATH=", GdmDefaultPath, NULL)); - argv=gdm_arg_munch(cmd); - execvp(argv[0], argv); - syslog(LOG_ERR, _("gdm_exec_command: Failed starting: %s"), cmd); - exit(EXIT_FAILURE); - - case -1: - syslog(LOG_ERR, _("gdm_exec_command: Can't fork process!")); - break; - - default: - break; - }; + return (EXIT_SUCCESS); + } } /* Log error and abort master daemon */ void -gdm_fail(const gchar *format, ...) +gdm_fail (const gchar *format, ...) { va_list args; gchar *s; - va_start(args, format); - s=g_strdup_vprintf(format, args); - va_end(args); + va_start (args, format); + s = g_strdup_vprintf (format, args); + va_end (args); - syslog(LOG_ERR, s); - fprintf(stderr, s); - fprintf(stderr, "\n"); - fflush(stderr); + syslog (LOG_ERR, s); + fprintf (stderr, s); + fprintf (stderr, "\n"); + fflush (stderr); - g_free(s); - unlink(GdmPidFile); + g_free (s); + unlink (GdmPidFile); closelog(); - exit(EXIT_FAILURE); + exit (EXIT_FAILURE); } /* Log error and abort the slave daemon */ void -gdm_abort(const gchar *format, ...) +gdm_abort (const gchar *format, ...) { va_list args; gchar *s; - va_start(args, format); - s=g_strdup_vprintf(format, args); - va_end(args); + va_start (args, format); + s = g_strdup_vprintf (format, args); + va_end (args); - syslog(LOG_ERR, s); + syslog (LOG_ERR, s); - g_free(s); + g_free (s); - exit(DISPLAY_ABORT); + exit (DISPLAY_ABORT); } /* Remanage display */ void -gdm_remanage(const gchar *format, ...) +gdm_remanage (const gchar *format, ...) { va_list args; gchar *s; - va_start(args, format); - s=g_strdup_vprintf(format, args); - va_end(args); + va_start (args, format); + s = g_strdup_vprintf (format, args); + va_end (args); - syslog(LOG_ERR, s); + syslog (LOG_ERR, s); - g_free(s); + g_free (s); - exit(DISPLAY_REMANAGE); + exit (DISPLAY_REMANAGE); } /* Log non fatal error/message */ void -gdm_info(const gchar *format, ...) +gdm_info (const gchar *format, ...) { va_list args; gchar *s; - va_start(args, format); - s=g_strdup_vprintf(format, args); - va_end(args); + va_start (args, format); + s = g_strdup_vprintf (format, args); + va_end (args); - syslog(LOG_INFO, s); + syslog (LOG_INFO, s); - g_free(s); + g_free (s); } /* Log error condition */ void -gdm_error(const gchar *format, ...) +gdm_error (const gchar *format, ...) { va_list args; gchar *s; - va_start(args, format); - s=g_strdup_vprintf(format, args); - va_end(args); + va_start (args, format); + s = g_strdup_vprintf (format, args); + va_end (args); - syslog(LOG_ERR, s); + syslog (LOG_ERR, s); - g_free(s); + g_free (s); } /* Log debug messages */ void -gdm_debug(const gchar *format, ...) +gdm_debug (const gchar *format, ...) { va_list args; gchar *s; - if(GdmDebug) { - va_start(args, format); - s=g_strdup_vprintf(format, args); - va_end(args); - - syslog(LOG_DEBUG, s); + if (GdmDebug) { + va_start (args, format); + s = g_strdup_vprintf (format, args); + va_end (args); + + /* FIXME */ + syslog (LOG_ERR, s); - g_free(s); + g_free (s); } } -void -gdm_putenv(gchar *s) -{ - putenv(s); - g_free(s); -} - - /* EOF */ |