Last active
December 14, 2015 12:24
-
-
Save aaron-em/ebb8f9f6bdb1c3b9de9e to your computer and use it in GitHub Desktop.
A patch for Emacs 24.5 to add a `--nofork' command line option, which turns out to be kinda useless but hey it's neat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- src/emacs-dist.c 2015-07-17 08:33:53.065388047 -0400 | |
+++ src/emacs.c 2015-07-17 09:54:39.085327207 -0400 | |
@@ -1012,6 +1012,13 @@ | |
#ifndef DOS_NT | |
pid_t f; | |
+ int no_fork = 0; | |
+ | |
+ if (argmatch(argv, argc, "-nofork", "--nofork", 5, NULL, &skip_args)) { | |
+ fprintf(stderr, "Daemon won't background itself.\n"); | |
+ no_fork = 1; | |
+ } | |
+ | |
/* Start as a daemon: fork a new child process which will run the | |
rest of the initialization code, then exit. | |
@@ -1045,10 +1052,12 @@ | |
Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\ | |
Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n"); | |
#endif /* USE_GTK */ | |
- f = fork (); | |
+ if (!no_fork) { | |
+ f = fork (); | |
+ } | |
#else /* DAEMON_MUST_EXEC */ | |
- if (!dname_arg || !strchr (dname_arg, '\n')) | |
- f = fork (); /* in orig */ | |
+ if (!no_fork && (!dname_arg || !strchr (dname_arg, '\n'))) | |
+ f = fork (); /* in orig */ | |
else | |
f = 0; /* in exec'd */ | |
#endif /* !DAEMON_MUST_EXEC */ | |
@@ -1058,7 +1067,9 @@ | |
char buf[1]; | |
/* Close unused writing end of the pipe. */ | |
- emacs_close (daemon_pipe[1]); | |
+ if (!no_fork) { | |
+ emacs_close (daemon_pipe[1]); | |
+ } | |
/* Just wait for the child to close its end of the pipe. */ | |
do | |
@@ -1078,7 +1089,9 @@ | |
exit (1); | |
} | |
- emacs_close (daemon_pipe[0]); | |
+ if (!no_fork) { | |
+ emacs_close (daemon_pipe[0]); | |
+ } | |
exit (0); | |
} | |
if (f < 0) | |
@@ -1106,9 +1119,11 @@ | |
argv[skip_args] = fdStr; | |
- fcntl (daemon_pipe[0], F_SETFD, 0); | |
- fcntl (daemon_pipe[1], F_SETFD, 0); | |
- execvp (argv[0], argv); | |
+ if (!no_fork) { | |
+ fcntl (daemon_pipe[0], F_SETFD, 0); | |
+ fcntl (daemon_pipe[1], F_SETFD, 0); | |
+ execvp (argv[0], argv); | |
+ } | |
emacs_perror (argv[0]); | |
exit (errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE); | |
} | |
@@ -1130,10 +1145,13 @@ | |
if (dname_arg) | |
daemon_name = xstrdup (dname_arg); | |
- /* Close unused reading end of the pipe. */ | |
- emacs_close (daemon_pipe[0]); | |
+ if (!no_fork) { | |
+ /* Close unused reading end of the pipe. */ | |
+ emacs_close (daemon_pipe[0]); | |
+ /* Set new session (not parent's) */ | |
+ setsid (); | |
+ } | |
- setsid (); | |
#else /* DOS_NT */ | |
fprintf (stderr, "This platform does not support the -daemon flag.\n"); | |
exit (1); | |
@@ -1667,6 +1685,7 @@ | |
{ "-batch", "--batch", 100, 0 }, | |
{ "-script", "--script", 100, 1 }, | |
{ "-daemon", "--daemon", 99, 0 }, | |
+ { "-nofork", "--nofork", 98, 0 }, | |
{ "-help", "--help", 90, 0 }, | |
{ "-nl", "--no-loadup", 70, 0 }, | |
{ "-nsl", "--no-site-lisp", 65, 0 }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment