mirror of
https://github.com/troglobit/finit.git
synced 2026-10-30 12:50:34 +00:00
helpers.c:set_hostname() - Fix resource and memory leaks.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
2fdd64a2d8
commit
8247344f0d
3 files changed
+15
-12
No files matched your search
@@ -250,7 +250,7 @@ int main(int argc, char* argv[])
|
|||||||
run("/sbin/sysctl -e -p /etc/sysctl.conf >/dev/null");
|
run("/sbin/sysctl -e -p /etc/sysctl.conf >/dev/null");
|
||||||
|
|
||||||
/* Set initial hostname. */
|
/* Set initial hostname. */
|
||||||
set_hostname(hostname);
|
set_hostname(&hostname);
|
||||||
|
|
||||||
ifconfig("lo", "127.0.0.1", "255.0.0.0", 1);
|
ifconfig("lo", "127.0.0.1", "255.0.0.0", 1);
|
||||||
if (network)
|
if (network)
|
||||||
|
|||||||
@@ -580,7 +580,7 @@ pid_t run_getty(char *cmd, char *args[], int console)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (console) {
|
if (console) {
|
||||||
i = write(STDERR_FILENO, msg, sizeof(msg));
|
(void)write(STDERR_FILENO, msg, sizeof(msg));
|
||||||
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
|
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -697,26 +697,29 @@ void do_sleep(unsigned int sec)
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_hostname(char *hostname)
|
void set_hostname(char **hostname)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
_d("Set hostname: %s", hostname);
|
_d("Set hostname: %s", *hostname);
|
||||||
if ((fp = fopen("/etc/hostname", "r")) != NULL) {
|
fp = fopen("/etc/hostname", "r");
|
||||||
|
if (fp) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
fstat(fileno(fp), &st);
|
fstat(fileno(fp), &st);
|
||||||
hostname = realloc(hostname, st.st_size);
|
*hostname = realloc(*hostname, st.st_size);
|
||||||
if (!hostname)
|
if (!*hostname) {
|
||||||
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fgets(hostname, st.st_size, fp);
|
fgets(*hostname, st.st_size, fp);
|
||||||
chomp(hostname);
|
chomp(*hostname);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostname)
|
if (*hostname)
|
||||||
sethostname(hostname, strlen(hostname));
|
sethostname(*hostname, strlen(*hostname));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ void chomp (char *str);
|
|||||||
void do_sleep (unsigned int sec);
|
void do_sleep (unsigned int sec);
|
||||||
int getuser (char *username);
|
int getuser (char *username);
|
||||||
int getgroup (char *group);
|
int getgroup (char *group);
|
||||||
void set_hostname (char *hostname);
|
void set_hostname (char **hostname);
|
||||||
|
|
||||||
int complete (char *cmd, int pid);
|
int complete (char *cmd, int pid);
|
||||||
int run (char *cmd);
|
int run (char *cmd);
|
||||||
|
|||||||
Reference in new issue
Block a user