~binli/ubuntu/trusty/cups/from-xenial

« back to all changes in this revision

Viewing changes to debian/patches/pidfile.patch

  • Committer: Bin Li
  • Date: 2017-03-07 06:11:18 UTC
  • Revision ID: bin.li@canonical.com-20170307061118-n3d3wp36al9zoz17
Init version from 16.04

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: Add support for creating pid files.
 
2
Author: Martin Pitt <mpitt@debian.org>
 
3
Bug: http://www.cups.org/str.php?L2465
 
4
 
 
5
Last-Update: 2015-02-10
 
6
 
 
7
--- a/scheduler/conf.c
 
8
+++ b/scheduler/conf.c
 
9
@@ -162,7 +162,8 @@
 
10
 #ifdef HAVE_AUTHORIZATION_H
 
11
   { "SystemGroupAuthKey",      &SystemGroupAuthKey,    CUPSD_VARTYPE_STRING },
 
12
 #endif /* HAVE_AUTHORIZATION_H */
 
13
-  { "TempDir",                 &TempDir,               CUPSD_VARTYPE_PATHNAME }
 
14
+  { "TempDir",                 &TempDir,               CUPSD_VARTYPE_PATHNAME },
 
15
+  { "PidFile",                 &PidFile,               CUPSD_VARTYPE_STRING }
 
16
 };
 
17
 
 
18
 static int             default_auth_type = CUPSD_AUTH_AUTO;
 
19
@@ -627,6 +628,7 @@
 
20
   cupsdSetStringf(&ServerHeader, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR,
 
21
                   CUPS_VERSION_MINOR);
 
22
   cupsdSetString(&StateDir, CUPS_STATEDIR);
 
23
+  cupsdSetString(&PidFile, "/var/run/cups/cupsd.pid");
 
24
 
 
25
   if (!strcmp(CUPS_DEFAULT_PRINTCAP, "/etc/printers.conf"))
 
26
     PrintcapFormat = PRINTCAP_SOLARIS;
 
27
@@ -3505,6 +3507,7 @@
 
28
              !_cups_strcasecmp(line, "SystemGroup") ||
 
29
              !_cups_strcasecmp(line, "SystemGroupAuthKey") ||
 
30
              !_cups_strcasecmp(line, "TempDir") ||
 
31
+             !_cups_strcasecmp(line, "PidFile") ||
 
32
             !_cups_strcasecmp(line, "User"))
 
33
     {
 
34
       cupsdLogMessage(CUPSD_LOG_INFO,
 
35
--- a/scheduler/conf.h
 
36
+++ b/scheduler/conf.h
 
37
@@ -245,6 +245,8 @@
 
38
 VAR char               *ServerKeychain         VALUE(NULL);
 
39
                                        /* Keychain holding cert + key */
 
40
 #endif /* HAVE_SSL */
 
41
+VAR char               *PidFile                VALUE(NULL);
 
42
+                                       /* Debian CUPS pid file */
 
43
 
 
44
 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
 
45
 VAR int                        IdleExitTimeout         VALUE(60);
 
46
--- a/scheduler/main.c
 
47
+++ b/scheduler/main.c
 
48
@@ -79,6 +79,8 @@
 
49
 static void            service_checkout(void);
 
50
 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
 
51
 static void            usage(int status) __attribute__((noreturn));
 
52
+int                    write_pid(void);
 
53
+int                    remove_pid(void);
 
54
 
 
55
 
 
56
 /*
 
57
@@ -664,6 +666,11 @@
 
58
     cupsdStartSystemMonitor();
 
59
 #endif /* __APPLE__ */
 
60
 
 
61
+  if (write_pid() == 0) {
 
62
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to write pid file");
 
63
+    return (1);
 
64
+  }
 
65
+
 
66
  /*
 
67
   * Send server-started event...
 
68
   */
 
69
@@ -1162,10 +1169,41 @@
 
70
 
 
71
   cupsdStopSelect();
 
72
 
 
73
+  remove_pid();
 
74
+
 
75
   return (!stop_scheduler);
 
76
 }
 
77
 
 
78
 
 
79
+/* 'write_pid()' - Write PID file.
 
80
+   'remove_pid()' - Delete PID file.
 
81
+*/
 
82
+int
 
83
+write_pid()
 
84
+{
 
85
+  FILE *f;
 
86
+  int fd;
 
87
+  int pid;
 
88
+  if (((fd = open(PidFile, O_RDWR|O_CREAT, 0644)) == -1)
 
89
+      || ((f = fdopen(fd, "r+")) == NULL) ) {
 
90
+    return 0;
 
91
+  }
 
92
+  pid = getpid();
 
93
+  if (!fprintf(f, "%d\n", pid)) {
 
94
+    close(fd);
 
95
+    return 0;
 
96
+  }
 
97
+  fflush(f);
 
98
+  close(fd);
 
99
+
 
100
+  return pid;
 
101
+}
 
102
+
 
103
+int
 
104
+remove_pid() {
 
105
+  return unlink(PidFile);
 
106
+}
 
107
+
 
108
 /*
 
109
  * 'cupsdAddString()' - Copy and add a string to an array.
 
110
  */
 
111
--- a/test/run-stp-tests.sh
 
112
+++ b/test/run-stp-tests.sh
 
113
@@ -541,6 +541,7 @@
 
114
 DocumentRoot $root/doc
 
115
 RequestRoot $BASE/spool
 
116
 TempDir $BASE/spool/temp
 
117
+PidFile $BASE/cupsd.pid
 
118
 AccessLog $BASE/log/access_log
 
119
 ErrorLog $BASE/log/error_log
 
120
 PageLog $BASE/log/page_log