aboutsummaryrefslogtreecommitdiff
path: root/net-p2p/uhub/files/patch-main.c_add_pid
diff options
context:
space:
mode:
Diffstat (limited to 'net-p2p/uhub/files/patch-main.c_add_pid')
-rw-r--r--net-p2p/uhub/files/patch-main.c_add_pid91
1 files changed, 91 insertions, 0 deletions
diff --git a/net-p2p/uhub/files/patch-main.c_add_pid b/net-p2p/uhub/files/patch-main.c_add_pid
new file mode 100644
index 000000000000..835256e4212a
--- /dev/null
+++ b/net-p2p/uhub/files/patch-main.c_add_pid
@@ -0,0 +1,91 @@
+--- src/main.c.orig 2009-11-06 11:02:57.000000000 +0300
++++ src/main.c 2009-11-06 11:15:45.000000000 +0300
+@@ -29,6 +29,7 @@
+ static const char* arg_gid = 0;
+ static const char* arg_config = 0;
+ static const char* arg_log = 0;
++static const char* arg_pid = 0;
+ static int arg_log_syslog = 0;
+
+
+@@ -214,6 +215,7 @@
+ #ifndef WIN32
+ " -u <user> Run as given user\n"
+ " -g <group> Run with given group permissions\n"
++ " -p <file> Store pid in file (process id)\n"
+ #endif
+ " -V Show version number.\n"
+ );
+@@ -225,7 +227,7 @@
+ void parse_command_line(int argc, char** argv)
+ {
+ int opt;
+- while ((opt = getopt(argc, argv, "vqfc:l:hu:g:VCsSL")) != -1)
++ while ((opt = getopt(argc, argv, "vqfc:l:hu:g:VCsSLp:")) != -1)
+ {
+ switch (opt)
+ {
+@@ -285,6 +287,10 @@
+ arg_gid = optarg;
+ break;
+
++ case 'p':
++ arg_pid = optarg;
++ break;
++
+ default:
+ print_usage(argv[0]);
+ break;
+@@ -386,6 +392,32 @@
+
+ return 0;
+ }
++
++int pidfile_create()
++{
++ if (arg_pid)
++ {
++ FILE* pidfile = fopen(arg_pid, "w");
++ if (!pidfile)
++ {
++ hub_log(log_fatal, "Unable to write pid file: %s\n", arg_pid);
++ return -1;
++ }
++ fprintf(pidfile, "%d", (int) getpid());
++ fclose(pidfile);
++ }
++ return 0;
++}
++
++int pidfile_destroy()
++{
++ if (arg_pid)
++ {
++ return unlink(arg_pid);
++ }
++ return 0;
++}
++
+ #endif /* WIN32 */
+
+
+@@ -421,11 +453,19 @@
+ }
+ }
+
++ if (pidfile_create() == -1)
++ return -1;
++
+ if (drop_privileges() == -1)
+ return -1;
+ #endif /* WIN32 */
+
+ ret = main_loop();
++
++#ifndef WIN32
++ pidfile_destroy();
++#endif
++
+ return ret;
+ }
+