~ubuntu-branches/ubuntu/saucy/syslog-ng/saucy

« back to all changes in this revision

Viewing changes to lib/gprocess.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2011-11-15 08:48:02 UTC
  • mfrom: (26.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111115084802-n0jegdnjlxk0m26s
Tags: 3.3.1.dfsg-1ubuntu1
* debian/control: remove libsystemd-daemon-dev build-depends
* debian/rules: remove --with-systemdsystemunitdir from
  override_dh_auto_configure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
static gint init_result_pipe[2] = { -1, -1 };
99
99
static GProcessKind process_kind = G_PK_STARTUP;
100
100
static gboolean stderr_present = TRUE;
 
101
static int have_capsyslog = FALSE;
101
102
 
102
103
/* global variables */
103
104
static struct
216
217
  if (!process_opts.caps)
217
218
    return TRUE;
218
219
 
 
220
  /*
 
221
   * if libcap or kernel doesn't support cap_syslog, then resort to
 
222
   * cap_sys_admin
 
223
   */
 
224
  if (capability == CAP_SYSLOG && (!have_capsyslog || CAP_SYSLOG == -1))
 
225
    capability = CAP_SYS_ADMIN;
 
226
 
219
227
  caps = cap_get_proc();
220
228
  if (!caps)
221
229
    return FALSE;
297
305
  return;
298
306
}
299
307
 
 
308
#ifndef PR_CAPBSET_READ
 
309
 
 
310
/* old glibc versions don't have PR_CAPBSET_READ, we define it to the
 
311
 * value as defined in newer versions. */
 
312
 
 
313
#define PR_CAPBSET_READ 23
 
314
#endif
 
315
 
 
316
gboolean
 
317
g_process_check_cap_syslog(void)
 
318
{
 
319
  int ret;
 
320
 
 
321
  if (have_capsyslog)
 
322
    return TRUE;
 
323
 
 
324
  if (CAP_SYSLOG == -1)
 
325
    return FALSE;
 
326
 
 
327
  ret = prctl(PR_CAPBSET_READ, CAP_SYSLOG);
 
328
  if (ret == -1)
 
329
    return FALSE;
 
330
 
 
331
  ret = cap_from_name("cap_syslog", NULL);
 
332
  if (ret == -1)
 
333
    {
 
334
      fprintf (stderr, "CAP_SYSLOG seems to be supported by the system, but "
 
335
               "libcap can't parse it. Falling back to CAP_SYS_ADMIN!\n");
 
336
      return FALSE;
 
337
    }
 
338
 
 
339
  have_capsyslog = TRUE;
 
340
  return TRUE;
 
341
}
 
342
 
300
343
#endif
301
344
 
302
345
/**
869
912
      if (!cwd)
870
913
        cwd = PATH_PIDFILEDIR;
871
914
        
872
 
      if (cwd && chdir(cwd) < 0)
873
 
        ;
 
915
      if (cwd)
 
916
        if (chdir(cwd))
 
917
          g_process_message("Error changing to directory=%s, errcode=%d", cwd, errno);
874
918
    }
875
919
    
876
920
  /* this check is here to avoid having to change directory early in the startup process */
1295
1339
    }
1296
1340
    
1297
1341
  /* daemon process, we should return to the caller to perform work */
1298
 
  
1299
 
  setsid();
 
1342
  /* Only call setsid() for backgrounded processes. */
 
1343
  if (process_opts.mode != G_PM_FOREGROUND)
 
1344
    {
 
1345
          setsid();
 
1346
    }
1300
1347
  
1301
1348
  /* NOTE: we need to signal the parent in case of errors from this point. 
1302
1349
   * This is accomplished by writing the appropriate exit code to