slcand: replace char pointers with static char buffers
The buffers to build the pathnames had been malloc'ed and never been free'd. This patch removes the malloc stuff entirely. Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>pull/7/head
parent
3a9baeda05
commit
c9cdc9d069
18
slcand.c
18
slcand.c
|
|
@ -63,6 +63,12 @@
|
||||||
/* Change this to the user under which to run */
|
/* Change this to the user under which to run */
|
||||||
#define RUN_AS_USER "root"
|
#define RUN_AS_USER "root"
|
||||||
|
|
||||||
|
/* The length of ttypath buffer */
|
||||||
|
#define TTYPATH_LENGTH 64
|
||||||
|
|
||||||
|
/* The length of pidfile name buffer */
|
||||||
|
#define PIDFILE_LENGTH 64
|
||||||
|
|
||||||
#define EXIT_SUCCESS 0
|
#define EXIT_SUCCESS 0
|
||||||
#define EXIT_FAILURE 1
|
#define EXIT_FAILURE 1
|
||||||
|
|
||||||
|
|
@ -99,9 +105,9 @@ static void daemonize (const char *lockfile, char *tty, char *name)
|
||||||
FILE * pFile;
|
FILE * pFile;
|
||||||
char const *pidprefix = "/var/run/";
|
char const *pidprefix = "/var/run/";
|
||||||
char const *pidsuffix = ".pid";
|
char const *pidsuffix = ".pid";
|
||||||
char *pidfile;
|
char pidfile[PIDFILE_LENGTH];
|
||||||
pidfile = malloc((strlen(pidprefix) +strlen(DAEMON_NAME) + strlen(tty) + strlen(pidsuffix) + 1) * sizeof(char));
|
|
||||||
sprintf(pidfile, "%s%s-%s%s", pidprefix, DAEMON_NAME, tty, pidsuffix);
|
snprintf(pidfile, PIDFILE_LENGTH, "%s%s-%s%s", pidprefix, DAEMON_NAME, tty, pidsuffix);
|
||||||
|
|
||||||
/* already a daemon */
|
/* already a daemon */
|
||||||
if (getppid () == 1)
|
if (getppid () == 1)
|
||||||
|
|
@ -209,7 +215,7 @@ static void daemonize (const char *lockfile, char *tty, char *name)
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *tty = NULL;
|
char *tty = NULL;
|
||||||
char *ttypath;
|
char ttypath[TTYPATH_LENGTH];
|
||||||
char const *devprefix = "/dev/";
|
char const *devprefix = "/dev/";
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
char buf[IFNAMSIZ+1];
|
char buf[IFNAMSIZ+1];
|
||||||
|
|
@ -235,8 +241,8 @@ int main (int argc, char *argv[])
|
||||||
if (pch == tty) {
|
if (pch == tty) {
|
||||||
print_usage(argv[0]);
|
print_usage(argv[0]);
|
||||||
}
|
}
|
||||||
ttypath = malloc((strlen(devprefix) + strlen(tty)) * sizeof(char));
|
|
||||||
sprintf (ttypath, "%s%s", devprefix, tty);
|
snprintf (ttypath, TTYPATH_LENGTH, "%s%s", devprefix, tty);
|
||||||
syslog (LOG_INFO, "starting on TTY device %s", ttypath);
|
syslog (LOG_INFO, "starting on TTY device %s", ttypath);
|
||||||
|
|
||||||
/* Daemonize */
|
/* Daemonize */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue