~jamesodhunt/upstart/bug-1197225

« back to all changes in this revision

Viewing changes to extra/upstart-file-bridge.c

  • Committer: James Hunt
  • Date: 2013-07-03 08:26:23 UTC
  • Revision ID: james.hunt@ubuntu.com-20130703082623-3zpymf1mb9uv7vvg
* extra/upstart-dbus-bridge.c: main(): Check nih_str_split() return.
* extra/upstart-event-bridge.c: main(): Check nih_str_split() return.
* extra/upstart-file-bridge.c: main():
  - Check nih_str_split() return.
  - Only attempt to extract PID from UPSTART_SESSION in user mode.

Show diffs side-by-side

added added

removed removed

Lines of Context:
547
547
                 * the Upstart instance (last part of the DBus path) in the filename.
548
548
                 */
549
549
 
550
 
                /* Extract PID from UPSTART_SESSION */
551
 
                user_session_path = nih_str_split (NULL, user_session_addr, "/", TRUE);
552
 
                for (int i = 0; user_session_path[i] != NULL; i++)
553
 
                        path_element = user_session_path[i];
554
 
 
555
 
                if (! path_element) {
556
 
                        nih_fatal (_("Invalid value for UPSTART_SESSION"));
557
 
                        exit (1);
558
 
                }
559
 
 
560
 
                pidfile_path = getenv ("XDG_RUNTIME_DIR");
561
 
                if (! pidfile_path)
562
 
                        pidfile_path = getenv ("HOME");
563
 
 
564
 
                if (pidfile_path) {
565
 
                        NIH_MUST (nih_strcat_sprintf (&pidfile, NULL, "%s/upstart-file-bridge.%s.pid",
566
 
                                                                pidfile_path, path_element));
567
 
                        nih_main_set_pidfile (pidfile);
 
550
                if (user) {
 
551
 
 
552
                        /* Extract PID from UPSTART_SESSION */
 
553
                        user_session_path = nih_str_split (NULL, user_session_addr, "/", TRUE);
 
554
 
 
555
                        for (int i = 0; user_session_path && user_session_path[i]; i++)
 
556
                                path_element = user_session_path[i];
 
557
 
 
558
                        if (! path_element) {
 
559
                                nih_fatal (_("Invalid value for UPSTART_SESSION"));
 
560
                                exit (1);
 
561
                        }
 
562
 
 
563
                        pidfile_path = getenv ("XDG_RUNTIME_DIR");
 
564
                        if (! pidfile_path)
 
565
                                pidfile_path = getenv ("HOME");
 
566
 
 
567
                        if (pidfile_path) {
 
568
                                NIH_MUST (nih_strcat_sprintf (&pidfile, NULL, "%s/upstart-file-bridge.%s.pid",
 
569
                                                        pidfile_path, path_element));
 
570
                                nih_main_set_pidfile (pidfile);
 
571
                        }
568
572
                }
569
573
 
570
574
                if (nih_main_daemonise () < 0) {