MCPcopy Create free account
hub / github.com/apache/httpd / ap_log_pid

Function ap_log_pid

server/log.c:1636–1701  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1634}
1635
1636AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename)
1637{
1638 apr_file_t *pid_file = NULL;
1639 apr_finfo_t finfo;
1640 static pid_t saved_pid = -1;
1641 pid_t mypid;
1642 apr_status_t rv;
1643 const char *fname;
1644 char *temp_fname;
1645 apr_fileperms_t perms;
1646 char pidstr[64];
1647
1648 if (!filename) {
1649 return;
1650 }
1651
1652 fname = ap_server_root_relative(p, filename);
1653 if (!fname) {
1654 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
1655 ap_server_conf, APLOGNO(00097) "Invalid PID file path %s, ignoring.", filename);
1656 return;
1657 }
1658
1659 mypid = getpid();
1660 if (mypid != saved_pid
1661 && apr_stat(&finfo, fname, APR_FINFO_MTIME, p) == APR_SUCCESS) {
1662 /* AP_SIG_GRACEFUL and HUP call this on each restart.
1663 * Only warn on first time through for this pid.
1664 *
1665 * XXX: Could just write first time through too, although
1666 * that may screw up scripts written to do something
1667 * based on the last modification time of the pid file.
1668 */
1669 ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, p, APLOGNO(00098)
1670 "pid file %s overwritten -- Unclean "
1671 "shutdown of previous Apache run?",
1672 fname);
1673 }
1674
1675 temp_fname = apr_pstrcat(p, fname, ".XXXXXX", NULL);
1676 rv = apr_file_mktemp(&pid_file, temp_fname,
1677 APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE, p);
1678 if (rv != APR_SUCCESS) {
1679 ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, APLOGNO(00099)
1680 "could not create %s", temp_fname);
1681 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(00100)
1682 "%s: could not log pid to file %s",
1683 ap_server_argv0, fname);
1684 exit(1);
1685 }
1686
1687 apr_snprintf(pidstr, sizeof pidstr, "%" APR_PID_T_FMT APR_EOL_STR, mypid);
1688
1689 perms = APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD;
1690 if (((rv = apr_file_perms_set(temp_fname, perms)) != APR_SUCCESS && rv != APR_ENOTIMPL)
1691 || (rv = apr_file_write_full(pid_file, pidstr, strlen(pidstr), NULL)) != APR_SUCCESS
1692 || (rv = apr_file_close(pid_file)) != APR_SUCCESS
1693 || (rv = apr_file_rename(temp_fname, fname, p)) != APR_SUCCESS) {

Callers 5

prefork_runFunction · 0.85
mpmt_os2_runFunction · 0.85
worker_runFunction · 0.85
winnt_post_configFunction · 0.85
event_runFunction · 0.85

Calls 2

ap_server_root_relativeFunction · 0.85
ap_log_errorFunction · 0.50

Tested by

no test coverage detected