updated on Tue Jan 10 04:01:21 UTC 2012
[aur-mirror.git] / urfkill / daemon_patch.diff
blob65e465705ecc142da89a6c59178edbffc8a6e768
1 diff --git a/src/urf-main.c b/src/urf-main.c
2 index 6c0907d..0a3e547 100644
3 --- a/src/urf-main.c
4 +++ b/src/urf-main.c
5 @@ -149,10 +149,12 @@ main (gint argc, gchar **argv)
6 gint retval = 1;
7 gboolean timed_exit = FALSE;
8 gboolean immediate_exit = FALSE;
9 + gboolean fork_daemon = FALSE;
10 guint timer_id = 0;
11 struct passwd *user;
12 const char *username = NULL;
13 const char *conf_file = NULL;
14 + pid_t pid;
16 const GOptionEntry options[] = {
17 { "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit,
18 @@ -161,6 +163,9 @@ main (gint argc, gchar **argv)
19 { "immediate-exit", '\0', 0, G_OPTION_ARG_NONE, &immediate_exit,
20 /* TRANSLATORS: exit straight away, used for automatic profiling */
21 _("Exit after the engine has loaded"), NULL },
22 + { "fork", 'f', 0, G_OPTION_ARG_NONE, &fork_daemon,
23 + /* TRANSLATORS: fork to background */
24 + _("Fork on startup"), NULL },
25 { "user", 'u', 0, G_OPTION_ARG_STRING, &username,
26 /* TRANSLATORS: change to another user and drop the privilege */
27 _("Use a specific user instead of root"), NULL },
28 @@ -260,6 +265,21 @@ main (gint argc, gchar **argv)
29 if (immediate_exit)
30 g_timeout_add (50, (GSourceFunc) urf_main_timed_exit_cb, loop);
32 + /* fork as daemon Clone ourselves to make a child */
33 + if(fork_daemon){
34 + pid = fork();
36 + /* If the pid is less than zero,
37 + something went wrong when forking */
38 + /* If the pid we got back was greater
39 + than zero, then the clone was
40 + successful and we are the parent. */
41 + if (pid < 0||pid > 0) {
42 + return pid;
43 + }
44 + /* If execution reaches this point we are the child */
45 + }
47 /* wait for input or timeout */
48 g_main_loop_run (loop);
49 retval = 0;