/*
- * Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2 of the License.
- *
- * 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 more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
*
+ * 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 more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include "udev.h"
#include "udev_rules.h"
-
static void kernel_log(struct ifreq ifr)
{
int klog;
sk = socket(PF_INET, SOCK_DGRAM, 0);
if (sk < 0) {
- err(udevice->udev, "error opening socket: %s\n", strerror(errno));
+ err(udevice->udev, "error opening socket: %m\n");
return -1;
}
memset(&ifr, 0x00, sizeof(struct ifreq));
- strlcpy(ifr.ifr_name, udevice->dev->kernel, IFNAMSIZ);
- strlcpy(ifr.ifr_newname, udevice->name, IFNAMSIZ);
+ util_strlcpy(ifr.ifr_name, udevice->dev->kernel, IFNAMSIZ);
+ util_strlcpy(ifr.ifr_newname, udevice->name, IFNAMSIZ);
retval = ioctl(sk, SIOCSIFNAME, &ifr);
if (retval == 0)
kernel_log(ifr);
/* see if the destination interface name already exists */
if (errno != EEXIST) {
- err(udevice->udev, "error changing netif name %s to %s: %s\n", ifr.ifr_name, ifr.ifr_newname, strerror(errno));
+ err(udevice->udev, "error changing netif name %s to %s: %m\n",
+ ifr.ifr_name, ifr.ifr_newname);
goto exit;
}
/* free our own name, another process may wait for us */
- strlcpy(ifr.ifr_newname, udevice->dev->kernel, IFNAMSIZ);
- strlcat(ifr.ifr_newname, "_rename", IFNAMSIZ);
+ util_strlcpy(ifr.ifr_newname, udevice->dev->kernel, IFNAMSIZ);
+ util_strlcat(ifr.ifr_newname, "_rename", IFNAMSIZ);
retval = ioctl(sk, SIOCSIFNAME, &ifr);
if (retval != 0) {
- err(udevice->udev, "error changing netif name %s to %s: %s\n", ifr.ifr_name, ifr.ifr_newname, strerror(errno));
+ err(udevice->udev, "error changing netif name %s to %s: %m\n",
+ ifr.ifr_name, ifr.ifr_newname);
goto exit;
}
/* wait 30 seconds for our target to become available */
- strlcpy(ifr.ifr_name, ifr.ifr_newname, IFNAMSIZ);
- strlcpy(ifr.ifr_newname, udevice->name, IFNAMSIZ);
+ util_strlcpy(ifr.ifr_name, ifr.ifr_newname, IFNAMSIZ);
+ util_strlcpy(ifr.ifr_newname, udevice->name, IFNAMSIZ);
loop = 30 * 20;
while (loop--) {
retval = ioctl(sk, SIOCSIFNAME, &ifr);
}
if (errno != EEXIST) {
- err(udevice->udev, "error changing net interface name %s to %s: %s\n",
- ifr.ifr_name, ifr.ifr_newname, strerror(errno));
+ err(udevice->udev, "error changing net interface name %s to %s: %m\n",
+ ifr.ifr_name, ifr.ifr_newname);
break;
}
- dbg(udevice->udev, "wait for netif '%s' to become free, loop=%i\n", udevice->name, (30 * 20) - loop);
+ dbg(udevice->udev, "wait for netif '%s' to become free, loop=%i\n",
+ udevice->name, (30 * 20) - loop);
usleep(1000 * 1000 / 20);
}
}
setenv("INTERFACE_OLD", udevice->dev->kernel, 1);
/* now change the devpath, because the kernel device name has changed */
- strlcpy(devpath, udevice->dev->devpath, sizeof(devpath));
+ util_strlcpy(devpath, udevice->dev->devpath, sizeof(devpath));
pos = strrchr(devpath, '/');
if (pos != NULL) {
pos[1] = '\0';
- strlcat(devpath, udevice->name, sizeof(devpath));
+ util_strlcat(devpath, udevice->name, sizeof(devpath));
sysfs_device_set_values(udevice->udev, udevice->dev, devpath, NULL, NULL);
setenv("DEVPATH", udevice->dev->devpath, 1);
setenv("INTERFACE", udevice->name, 1);
} else {
dbg(udevice->udev, "'%s' not found in database, using kernel name '%s'\n",
udevice->dev->devpath, udevice->dev->kernel);
- strlcpy(udevice->name, udevice->dev->kernel, sizeof(udevice->name));
+ util_strlcpy(udevice->name, udevice->dev->kernel, sizeof(udevice->name));
}
udev_rules_get_run(rules, udevice);