* Add some logging and forking tweaks to work better with systemd.
This commit is contained in:
parent
de15926f76
commit
2e120e83a0
37
log.c
37
log.c
@ -25,6 +25,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "upnpglobalvars.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
static FILE *log_fp = NULL;
|
static FILE *log_fp = NULL;
|
||||||
@ -123,11 +124,7 @@ log_init(const char *fname, const char *debug)
|
|||||||
void
|
void
|
||||||
log_err(int level, enum _log_facility facility, char *fname, int lineno, char *fmt, ...)
|
log_err(int level, enum _log_facility facility, char *fname, int lineno, char *fmt, ...)
|
||||||
{
|
{
|
||||||
//char errbuf[1024];
|
|
||||||
char * errbuf;
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
time_t t;
|
|
||||||
struct tm *tm;
|
|
||||||
|
|
||||||
if (level && level>log_level[facility] && level>E_FATAL)
|
if (level && level>log_level[facility] && level>E_FATAL)
|
||||||
return;
|
return;
|
||||||
@ -135,29 +132,33 @@ log_err(int level, enum _log_facility facility, char *fname, int lineno, char *f
|
|||||||
if (!log_fp)
|
if (!log_fp)
|
||||||
log_fp = stdout;
|
log_fp = stdout;
|
||||||
|
|
||||||
|
// timestamp
|
||||||
|
if (!GETFLAG(SYSTEMD_MASK))
|
||||||
|
{
|
||||||
|
time_t t;
|
||||||
|
struct tm *tm;
|
||||||
|
t = time(NULL);
|
||||||
|
tm = localtime(&t);
|
||||||
|
fprintf(log_fp, "[%04d/%02d/%02d %02d:%02d:%02d] ",
|
||||||
|
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
|
||||||
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (level)
|
||||||
|
fprintf(log_fp, "%s:%d: %s: ", fname, lineno, level_name[level]);
|
||||||
|
else
|
||||||
|
fprintf(log_fp, "%s:%d: ", fname, lineno);
|
||||||
|
|
||||||
// user log
|
// user log
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
//vsnprintf(errbuf, sizeof(errbuf), fmt, ap);
|
if (vfprintf(log_fp, fmt, ap) == -1)
|
||||||
if (vasprintf(&errbuf, fmt, ap) == -1)
|
|
||||||
{
|
{
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
// timestamp
|
|
||||||
t = time(NULL);
|
|
||||||
tm = localtime(&t);
|
|
||||||
fprintf(log_fp, "[%04d/%02d/%02d %02d:%02d:%02d] ",
|
|
||||||
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
|
|
||||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
||||||
|
|
||||||
if (level)
|
|
||||||
fprintf(log_fp, "%s:%d: %s: %s", fname, lineno, level_name[level], errbuf);
|
|
||||||
else
|
|
||||||
fprintf(log_fp, "%s:%d: %s", fname, lineno, errbuf);
|
|
||||||
fflush(log_fp);
|
fflush(log_fp);
|
||||||
free(errbuf);
|
|
||||||
|
|
||||||
if (level==E_FATAL)
|
if (level==E_FATAL)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
@ -668,7 +668,7 @@ no_exifdata:
|
|||||||
m.dlna_pn = strdup("JPEG_SM");
|
m.dlna_pn = strdup("JPEG_SM");
|
||||||
else if( width <= 1024 && height <= 768 )
|
else if( width <= 1024 && height <= 768 )
|
||||||
m.dlna_pn = strdup("JPEG_MED");
|
m.dlna_pn = strdup("JPEG_MED");
|
||||||
else if( (width <= 4096 && height <= 4096) || !(GETFLAG(DLNA_STRICT_MASK)) )
|
else if( (width <= 4096 && height <= 4096) || !GETFLAG(DLNA_STRICT_MASK) )
|
||||||
m.dlna_pn = strdup("JPEG_LRG");
|
m.dlna_pn = strdup("JPEG_LRG");
|
||||||
xasprintf(&m.resolution, "%dx%d", width, height);
|
xasprintf(&m.resolution, "%dx%d", width, height);
|
||||||
|
|
||||||
|
23
minidlna.c
23
minidlna.c
@ -930,6 +930,11 @@ init(int argc, char * * argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#ifdef __linux__
|
||||||
|
case 'S':
|
||||||
|
SETFLAG(SYSTEMD_MASK);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
case 'V':
|
case 'V':
|
||||||
printf("Version " MINIDLNA_VERSION "\n");
|
printf("Version " MINIDLNA_VERSION "\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -970,6 +975,9 @@ init(int argc, char * * argv)
|
|||||||
"\t-h displays this text\n"
|
"\t-h displays this text\n"
|
||||||
"\t-R forces a full rescan\n"
|
"\t-R forces a full rescan\n"
|
||||||
"\t-L do note create playlists\n"
|
"\t-L do note create playlists\n"
|
||||||
|
#ifdef __linux__
|
||||||
|
"\t-S changes behaviour for systemd\n"
|
||||||
|
#endif
|
||||||
"\t-V print the version number\n",
|
"\t-V print the version number\n",
|
||||||
argv[0], pidfilename);
|
argv[0], pidfilename);
|
||||||
return 1;
|
return 1;
|
||||||
@ -984,26 +992,33 @@ init(int argc, char * * argv)
|
|||||||
{
|
{
|
||||||
log_level = log_str;
|
log_level = log_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set the default log file path to NULL (stdout) */
|
||||||
|
path = NULL;
|
||||||
if(debug_flag)
|
if(debug_flag)
|
||||||
{
|
{
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
strcpy(log_str+65, "maxdebug");
|
strcpy(log_str+65, "maxdebug");
|
||||||
log_level = log_str;
|
log_level = log_str;
|
||||||
log_init(NULL, log_level);
|
}
|
||||||
|
else if(GETFLAG(SYSTEMD_MASK))
|
||||||
|
{
|
||||||
|
pid = getpid();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pid = daemonize();
|
pid = daemonize();
|
||||||
#ifdef READYNAS
|
#ifdef READYNAS
|
||||||
unlink("/ramfs/.upnp-av_scan");
|
unlink("/ramfs/.upnp-av_scan");
|
||||||
log_init("/var/log/upnp-av.log", log_level);
|
path = "/var/log/upnp-av.log";
|
||||||
#else
|
#else
|
||||||
if( access(db_path, F_OK) != 0 )
|
if( access(db_path, F_OK) != 0 )
|
||||||
make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
|
make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
|
||||||
sprintf(buf, "%s/minidlna.log", log_path);
|
snprintf(buf, sizeof(buf), "%s/minidlna.log", log_path);
|
||||||
log_init(buf, log_level);
|
path = buf;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
log_init(path, log_level);
|
||||||
|
|
||||||
if (checkforrunning(pidfilename) < 0)
|
if (checkforrunning(pidfilename) < 0)
|
||||||
{
|
{
|
||||||
|
@ -252,7 +252,8 @@ _asf_load_string(FILE *fp, int type, int size, char *buf, int len)
|
|||||||
case ASF_VT_UNICODE:
|
case ASF_VT_UNICODE:
|
||||||
for(j = 0; j < size; j += 2)
|
for(j = 0; j < size; j += 2)
|
||||||
{
|
{
|
||||||
wc = *(__s16*)&data[j];
|
wd16 = (__s16 *) &data[j];
|
||||||
|
wc = (__u16)*wd16;
|
||||||
i += utf16le_to_utf8(&buf[i], len - i, wc);
|
i += utf16le_to_utf8(&buf[i], len - i, wc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -188,9 +188,10 @@ extern uint32_t runtime_flags;
|
|||||||
#define TIVO_MASK 0x0002
|
#define TIVO_MASK 0x0002
|
||||||
#define DLNA_STRICT_MASK 0x0004
|
#define DLNA_STRICT_MASK 0x0004
|
||||||
#define NO_PLAYLIST_MASK 0x0008
|
#define NO_PLAYLIST_MASK 0x0008
|
||||||
|
#define SYSTEMD_MASK 0x0010
|
||||||
|
|
||||||
#define SETFLAG(mask) runtime_flags |= mask
|
#define SETFLAG(mask) runtime_flags |= mask
|
||||||
#define GETFLAG(mask) runtime_flags & mask
|
#define GETFLAG(mask) (runtime_flags & mask)
|
||||||
#define CLEARFLAG(mask) runtime_flags &= ~mask
|
#define CLEARFLAG(mask) runtime_flags &= ~mask
|
||||||
|
|
||||||
extern const char * pidfilename;
|
extern const char * pidfilename;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user