Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(RHEL-28191) rename_device: free path after it is used #478

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions src/rename_device.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/*
/*
* rename_device.c: udev helper to rename ethernet devices.
*
* Copyright (C) 2006-2009 Red Hat, Inc. All rights reserved.
Expand All @@ -9,8 +9,8 @@
* GNU General Public License v.2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
Expand Down Expand Up @@ -64,7 +64,7 @@ struct tmp *tmplist = NULL;
#if defined(__s390__) || defined(__s390x__)
static int is_cdev(const struct dirent *dent) {
char *end = NULL;

if (strncmp(dent->d_name,"cdev",4))
return 0;
strtoul(dent->d_name+4,&end, 10);
Expand All @@ -75,7 +75,7 @@ static int is_cdev(const struct dirent *dent) {

static inline char *getdev(char *path, char *ent) {
char *a, *b, *ret;

asprintf(&a,"%s/%s",path,ent);
b = canonicalize_file_name(a);
ret = strdup(basename(b));
Expand All @@ -88,13 +88,13 @@ char *read_subchannels(char *path) {
char *tmp, *ret;
int n, x;
struct dirent **cdevs;

if ((n = scandir(path, &cdevs, is_cdev, alphasort)) <= 0)
return NULL;

ret = getdev(path,cdevs[0]->d_name);
for (x = 1 ; x < n ; x++ ) {
if (asprintf(&tmp, "%s,%s", ret, getdev(path, cdevs[x]->d_name)) == -1)
for (x = 1 ; x < n ; x++ ) {
if (asprintf(&tmp, "%s,%s", ret, getdev(path, cdevs[x]->d_name)) == -1)
return NULL;
free(ret);
ret = tmp;
Expand Down Expand Up @@ -172,27 +172,28 @@ struct netdev *get_configs() {
struct netdev *ret, *tmpdev;
struct dirent **cfgs;
int x;

ret = NULL;

if ((ncfgs = scandir("/etc/sysconfig/network-scripts",&cfgs,
isCfg, alphasort)) == -1) {
return ret;
}
for (x = 0; x < ncfgs; x++ ) {
char *path;
char *path = NULL;
char *devname, *hwaddr;
int vlan;
gchar *contents, **lines;
int i;

devname = hwaddr = contents = NULL;
lines = NULL;
vlan = 0;
if (asprintf(&path,"/etc/sysconfig/network-scripts/%s",
cfgs[x]->d_name) == -1)
continue;
g_file_get_contents(path, &contents, NULL, NULL);
free(path);
if (!contents)
continue;
lines = g_strsplit(contents,"\n", 0);
Expand Down Expand Up @@ -235,7 +236,7 @@ struct netdev *get_configs() {
free(cfgs);
return ret;
}

char *get_hwaddr(char *device) {
char *path = NULL;
char *contents = NULL;
Expand All @@ -260,13 +261,13 @@ char *get_hwaddr(char *device) {

return g_strstrip(contents);
}

char *get_config_by_hwaddr(char *hwaddr, char *current) {
struct netdev *config;
char *first = NULL;

if (!hwaddr) return NULL;

for (config = configs; config; config = config->next) {
if (strcasecmp(config->hwaddr, hwaddr) != 0)
continue;
Expand Down Expand Up @@ -322,7 +323,7 @@ void take_lock() {
int count = 0;
int lockfd;
ssize_t ignored_retval __attribute__((unused));

while (1) {
lockfd = open(LOCKFILE, O_RDWR|O_CREAT|O_EXCL, 0644);
if (lockfd != -1) {
Expand All @@ -341,7 +342,7 @@ void take_lock() {
int fd;
char buf[32];
int pid;

fd = open(LOCKFILE, O_RDONLY);
if (fd == -1)
break;
Expand All @@ -364,16 +365,16 @@ int main(int argc, char **argv) {
struct timeval tv;

gettimeofday(&tv, NULL);
srand(tv.tv_usec);
srand(tv.tv_usec);
take_lock();

signal(SIGSEGV,sighandler);
signal(SIGKILL,sighandler);
signal(SIGTERM,sighandler);
signal(SIGSEGV,sighandler);
signal(SIGALRM,sighandler);
alarm(10);

src = getenv("INTERFACE");
if (!src)
goto out_unlock;
Expand All @@ -390,7 +391,7 @@ int main(int argc, char **argv) {
goto out_unlock;

printf("%s", target);

out_unlock:
unlink(LOCKFILE);
exit(0);
Expand Down
Loading