Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
e4fb2a94
Commit
e4fb2a94
authored
May 25, 2020
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor pid-file creation into a separate function.
parent
899ca1bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
23 deletions
+31
-23
mgt_main.c
bin/varnishd/mgt/mgt_main.c
+31
-23
No files found.
bin/varnishd/mgt/mgt_main.c
View file @
e4fb2a94
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
#include <ctype.h>
#include <ctype.h>
#include <fcntl.h>
#include <fcntl.h>
#include <signal.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
@@ -431,6 +432,32 @@ mgt_f_read(const char *fn)
...
@@ -431,6 +432,32 @@ mgt_f_read(const char *fn)
VTAILQ_INSERT_TAIL
(
&
f_args
,
fa
,
list
);
VTAILQ_INSERT_TAIL
(
&
f_args
,
fa
,
list
);
}
}
static
struct
vpf_fh
*
create_pid_file
(
pid_t
*
ppid
,
const
char
*
fmt
,
...)
{
struct
vsb
*
vsb
;
va_list
ap
;
struct
vpf_fh
*
pfh
;
va_start
(
ap
,
fmt
);
vsb
=
VSB_new_auto
();
AN
(
vsb
);
VSB_vprintf
(
vsb
,
fmt
,
ap
);
AZ
(
VSB_finish
(
vsb
));
VJ_master
(
JAIL_MASTER_FILE
);
pfh
=
VPF_Open
(
VSB_data
(
vsb
),
0644
,
ppid
);
if
(
pfh
==
NULL
&&
errno
==
EEXIST
)
ARGV_ERR
(
"Varnishd is already running (pid=%jd) (pidfile=%s)
\n
"
,
(
intmax_t
)
*
ppid
,
VSB_data
(
vsb
));
if
(
pfh
==
NULL
)
ARGV_ERR
(
"Could not open pid-file (%s): %s
\n
"
,
VSB_data
(
vsb
),
vstrerror
(
errno
));
VJ_master
(
JAIL_MASTER_LOW
);
VSB_destroy
(
&
vsb
);
return
(
pfh
);
}
int
int
main
(
int
argc
,
char
*
const
*
argv
)
main
(
int
argc
,
char
*
const
*
argv
)
{
{
...
@@ -764,29 +791,10 @@ main(int argc, char * const *argv)
...
@@ -764,29 +791,10 @@ main(int argc, char * const *argv)
dirname
,
vstrerror
(
errno
));
dirname
,
vstrerror
(
errno
));
}
}
vsb
=
VSB_new_auto
();
pfh1
=
create_pid_file
(
&
pid
,
"%s/_.pid"
,
dirname
);
AN
(
vsb
);
VSB_printf
(
vsb
,
"%s/_.pid"
,
dirname
);
if
(
P_arg
)
AZ
(
VSB_finish
(
vsb
));
pfh2
=
create_pid_file
(
&
pid
,
"%s"
,
P_arg
);
VJ_master
(
JAIL_MASTER_FILE
);
pfh1
=
VPF_Open
(
VSB_data
(
vsb
),
0644
,
&
pid
);
if
(
pfh1
==
NULL
&&
errno
==
EEXIST
)
ARGV_ERR
(
"Varnishd is already running (pid=%jd)
\n
"
,
(
intmax_t
)
pid
);
if
(
pfh1
==
NULL
)
ARGV_ERR
(
"Could not open pid-file (%s): %s
\n
"
,
VSB_data
(
vsb
),
vstrerror
(
errno
));
VSB_destroy
(
&
vsb
);
if
(
P_arg
)
{
pfh2
=
VPF_Open
(
P_arg
,
0644
,
&
pid
);
if
(
pfh2
==
NULL
&&
errno
==
EEXIST
)
ARGV_ERR
(
"Varnishd is already running (pid=%jd)
\n
"
,
(
intmax_t
)
pid
);
if
(
pfh2
==
NULL
)
ARGV_ERR
(
"Could not open pid-file (%s): %s
\n
"
,
P_arg
,
vstrerror
(
errno
));
}
VJ_master
(
JAIL_MASTER_LOW
);
/* If no -s argument specified, process default -s argument */
/* If no -s argument specified, process default -s argument */
if
(
!
s_arg_given
)
if
(
!
s_arg_given
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment