/[gentoo-x86]/net-misc/lldpd/files/lldpd-0.7.9-dont-fork-after-making-pidfile.patch
Gentoo

Contents of /net-misc/lldpd/files/lldpd-0.7.9-dont-fork-after-making-pidfile.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download) (as text)
Sat Jan 31 08:05:54 2015 UTC (5 years, 4 months ago) by chutzpah
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/x-diff
FILE REMOVED
Version bump, clean out old version.

(Portage version: 2.2.15/cvs/Linux x86_64, signed Manifest commit with key 0xE3F69979BB4B8928DA78E3D17CBF44EF)

1 chutzpah 1.1 diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c
2     index 4c32f27..09bee41 100644
3     --- a/src/daemon/lldpd.c
4     +++ b/src/daemon/lldpd.c
5     @@ -1264,7 +1264,7 @@ lldpd_main(int argc, char *argv[], char *envp[])
6     {
7     struct lldpd *cfg;
8     struct lldpd_chassis *lchassis;
9     - int ch, debug = 0;
10     + int ch, debug = 0, create_pid = 0;
11     #ifdef USE_SNMP
12     int snmp = 0;
13     char *agentx = NULL; /* AgentX socket */
14     @@ -1464,34 +1464,24 @@ lldpd_main(int argc, char *argv[], char *envp[])
15     /* Disable SIGPIPE */
16     signal(SIGPIPE, SIG_IGN);
17    
18     - /* Configuration with lldpcli */
19     - if (lldpcli) {
20     - log_debug("main", "invoking lldpcli for configuration");
21     - if (lldpd_configure(debug, lldpcli, ctlname) == -1)
22     - fatal("main", "unable to spawn lldpcli");
23     - }
24     -
25     /* Daemonization, unless started by upstart, systemd or launchd or debug */
26     #ifndef HOST_OS_OSX
27     if (!lldpd_started_by_upstart() && !lldpd_started_by_systemd() &&
28     !debug) {
29     - int pid;
30     - char *spid;
31     log_debug("main", "daemonize");
32     if (daemon(0, 0) != 0)
33     fatal("main", "failed to detach daemon");
34     - if ((pid = open(LLDPD_PID_FILE,
35     - O_TRUNC | O_CREAT | O_WRONLY, 0666)) == -1)
36     - fatal("main", "unable to open pid file " LLDPD_PID_FILE);
37     - if (asprintf(&spid, "%d\n", getpid()) == -1)
38     - fatal("main", "unable to create pid file " LLDPD_PID_FILE);
39     - if (write(pid, spid, strlen(spid)) == -1)
40     - fatal("main", "unable to write pid file " LLDPD_PID_FILE);
41     - free(spid);
42     - close(pid);
43     + create_pid++;
44     }
45     #endif
46    
47     + /* Configuration with lldpcli */
48     + if (lldpcli) {
49     + log_debug("main", "invoking lldpcli for configuration");
50     + if (lldpd_configure(debug, lldpcli, ctlname) == -1)
51     + fatal("main", "unable to spawn lldpcli");
52     + }
53     +
54     /* Try to read system information from /etc/os-release if possible.
55     Fall back to lsb_release for compatibility. */
56     log_debug("main", "get OS/LSB release information");
57     @@ -1501,7 +1491,7 @@ lldpd_main(int argc, char *argv[], char *envp[])
58     }
59    
60     log_debug("main", "initialize privilege separation");
61     - priv_init(PRIVSEP_CHROOT, ctl, uid, gid);
62     + priv_init(PRIVSEP_CHROOT, ctl, uid, gid, create_pid);
63    
64     /* Initialization of global configuration */
65     if ((cfg = (struct lldpd *)
66     diff --git a/src/daemon/lldpd.h b/src/daemon/lldpd.h
67     index 797623c..887ca9a 100644
68     --- a/src/daemon/lldpd.h
69     +++ b/src/daemon/lldpd.h
70     @@ -220,7 +220,7 @@ client_handle_client(struct lldpd *cfg,
71     int*);
72    
73     /* priv.c */
74     -void priv_init(const char*, int, uid_t, gid_t);
75     +void priv_init(const char*, int, uid_t, gid_t, int);
76     void priv_wait(void);
77     void priv_ctl_cleanup(const char *ctlname);
78     char *priv_gethostbyname(void);
79     diff --git a/src/daemon/priv.c b/src/daemon/priv.c
80     index b6341e4..9903bce 100644
81     --- a/src/daemon/priv.c
82     +++ b/src/daemon/priv.c
83     @@ -71,6 +71,24 @@ int res_init (void);
84     static int monitored = -1; /* Child */
85     #endif
86    
87     +/* make pidfile on Linux systems */
88     +void write_pidfile()
89     +{
90     +#ifndef HOST_OS_OSX
91     + int pid;
92     + char *spid;
93     +
94     + if ((pid = open(LLDPD_PID_FILE, O_TRUNC | O_CREAT | O_WRONLY, 0666)) == -1)
95     + fatal("main", "unable to open pid file " LLDPD_PID_FILE);
96     + if (asprintf(&spid, "%d\n", getpid()) == -1)
97     + fatal("main", "unable to create pid file " LLDPD_PID_FILE);
98     + if (write(pid, spid, strlen(spid)) == -1)
99     + fatal("main", "unable to write pid file " LLDPD_PID_FILE);
100     + free(spid);
101     + close(pid);
102     +#endif
103     +}
104     +
105     /* Proxies */
106     static void
107     priv_ping()
108     @@ -569,7 +587,7 @@ priv_setup_chroot(const char *chrootdir)
109     #endif
110    
111     void
112     -priv_init(const char *chrootdir, int ctl, uid_t uid, gid_t gid)
113     +priv_init(const char *chrootdir, int ctl, uid_t uid, gid_t gid, int create_pid)
114     {
115    
116     int pair[2];
117     @@ -587,6 +605,8 @@ priv_init(const char *chrootdir, int ctl, uid_t uid, gid_t gid)
118     /* Spawn off monitor */
119     if ((monitored = fork()) < 0)
120     fatal("privsep", "unable to fork monitor");
121     + if (create_pid != 0)
122     + write_pidfile();
123     switch (monitored) {
124     case 0:
125     /* We are in the children, drop privileges */
126     @@ -649,6 +669,8 @@ priv_init(const char *chrootdir, int ctl, uid_t uid, gid_t gid)
127     exit(0);
128     }
129     #else
130     + if (create_pid != 0)
131     + write_pidfile();
132     log_warnx("priv", "no privilege separation available");
133     priv_ping();
134     #endif

  ViewVC Help
Powered by ViewVC 1.1.20