Bug 60945 - Apache doesn't manage PidFile's properly
Summary: Apache doesn't manage PidFile's properly
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.5-HEAD
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-30 20:12 UTC by Ngie Cooper
Modified: 2017-03-30 22:32 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ngie Cooper 2017-03-30 20:12:47 UTC
We integrate apache into our work project, and we ran into an issue where the process management service (that tracks the apache process via the FreeBSD process table), said that the process had died, but because httpd hadn't removed the process on our version, it claimed that the PID file was open, so (in theory) the process itself was running (even though the process with the PID in the pidfile didn't correspond to the apache instance).

Getting to the point, PidFile management with apache is done improperly -- in particular, this logic doesn't keep the pidfile open (over the course of the worker process lifetime), and doesn't lock the pidfile with fcntl(2), or something similar via open(2):

1555     if ((rv = apr_file_open(&pid_file, fname,
1556                             APR_WRITE | APR_CREATE | APR_TRUNCATE,
1557                             APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, p))
1558         != APR_SUCCESS) {
1559         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, APLOGNO(00099)
1560                      "could not create %s", fname);
1561         ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(00100)
1562                      "%s: could not log pid to file %s",
1563                      ap_server_argv0, fname);
1564         exit(1);
1565     }
1566     apr_file_printf(pid_file, "%" APR_PID_T_FMT APR_EOL_STR, mypid);
1567     apr_file_close(pid_file);
1568     saved_pid = mypid;

FreeBSD has a set of shims for this that could be used (pidfile_open(3)), but unfortunately they're not portable as-is (just to the various BSD versions, with some minor adjustments).

Apache needs to learn how to do pid files properly so it can be managed properly. Otherwise, there's no point to having PidFile's per VirtualHost that cannot be managed.
Comment 1 Eric Covener 2017-03-30 20:33:47 UTC
> Apache needs to learn how to do pid files properly so it can be managed
> properly. Otherwise, there's no point to having PidFile's per VirtualHost
> that cannot be managed.

"PidFile" isn't syntactically valid inside of VirtualHost.  What's the relationship of this to the rest of the report?
Comment 2 Ngie Cooper 2017-03-30 22:32:31 UTC
(In reply to Eric Covener from comment #1)
> > Apache needs to learn how to do pid files properly so it can be managed
> > properly. Otherwise, there's no point to having PidFile's per VirtualHost
> > that cannot be managed.
> 
> "PidFile" isn't syntactically valid inside of VirtualHost.  What's the
> relationship of this to the rest of the report?

I'm sorry -- I misread the docs yesterday ( http://httpd.apache.org/docs/current/mod/mpm_common.html#pidfile ). It has nothing to do with VirtualHost directives (I misspoke in comment # 0).

Thanks!