chiark / gitweb /
everywhere: make use of new0() and macro() macros, and stop using perror()
[elogind.git] / src / libudev / libudev-queue-private.c
index ca6d229a2c91e50a450fe447ba230444e65fb61f..d5a2b503dd39c189cd7f792780c6262aa576de4b 100644 (file)
@@ -1,14 +1,22 @@
-/*
- * libudev - interface to udev device information
- *
- * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
- * Copyright (C) 2009 Alan Jenkins <alan-jenkins@tuffmail.co.uk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- */
+/***
+  This file is part of systemd.
+
+  Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
+  Copyright 2009 Alan Jenkins <alan-jenkins@tuffmail.co.uk>
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
 
 /*
  * DISCLAIMER - The file format mentioned here is private to udev/libudev,
@@ -71,7 +79,7 @@ struct udev_queue_export *udev_queue_export_new(struct udev *udev)
         if (udev == NULL)
                 return NULL;
 
-        udev_queue_export = calloc(1, sizeof(struct udev_queue_export));
+        udev_queue_export = new0(struct udev_queue_export, 1);
         if (udev_queue_export == NULL)
                 return NULL;
         udev_queue_export->udev = udev;
@@ -101,14 +109,10 @@ struct udev_queue_export *udev_queue_export_unref(struct udev_queue_export *udev
 
 void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export)
 {
-        char filename[UTIL_PATH_SIZE];
-
         if (udev_queue_export == NULL)
                 return;
-        util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL);
-        unlink(filename);
-        util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL);
-        unlink(filename);
+        unlink("/run/udev/queue.tmp");
+        unlink("/run/udev/queue.bin");
 }
 
 static int skip_to(FILE *file, long offset)
@@ -155,10 +159,10 @@ static struct queue_devpaths *build_index(struct udev_queue_export *udev_queue_e
         /* allocate the table */
         range = udev_queue_export->seqnum_min - udev_queue_export->seqnum_max;
         if (range - 1 > INT_MAX) {
-                err(udev_queue_export->udev, "queue file overflow\n");
+                udev_err(udev_queue_export->udev, "queue file overflow\n");
                 return NULL;
         }
-        devpaths = calloc(1, sizeof(struct queue_devpaths) + (range + 1) * sizeof(long));
+        devpaths = malloc0(sizeof(struct queue_devpaths) + (range + 1) * sizeof(long));
         if (devpaths == NULL)
                 return NULL;
         devpaths->devpaths_size = range + 1;
@@ -192,7 +196,7 @@ static struct queue_devpaths *build_index(struct udev_queue_export *udev_queue_e
         return devpaths;
 
 read_error:
-        err(udev_queue_export->udev, "queue file corrupted\n");
+        udev_err(udev_queue_export->udev, "queue file corrupted\n");
         free(devpaths);
         return NULL;
 }
@@ -201,8 +205,6 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export)
 {
         unsigned long long int seqnum;
         struct queue_devpaths *devpaths = NULL;
-        char filename[UTIL_PATH_SIZE];
-        char filename_tmp[UTIL_PATH_SIZE];
         FILE *new_queue_file = NULL;
         unsigned int i;
 
@@ -218,8 +220,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export)
         }
 
         /* create new queue file */
-        util_strscpyl(filename_tmp, sizeof(filename_tmp), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL);
-        new_queue_file = fopen(filename_tmp, "w+");
+        new_queue_file = fopen("/run/udev/queue.tmp", "w+e");
         if (new_queue_file == NULL)
                 goto error;
         seqnum = udev_queue_export->seqnum_max;
@@ -252,8 +253,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export)
                 goto error;
 
         /* rename the new file on top of the old one */
-        util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL);
-        if (rename(filename_tmp, filename) != 0)
+        if (rename("/run/udev/queue.tmp", "/run/udev/queue.bin") != 0)
                 goto error;
 
         if (udev_queue_export->queue_file != NULL)
@@ -264,7 +264,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export)
         return 0;
 
 error:
-        err(udev_queue_export->udev, "failed to create queue file: %m\n");
+        udev_err(udev_queue_export->udev, "failed to create queue file: %m\n");
         udev_queue_export_cleanup(udev_queue_export);
 
         if (udev_queue_export->queue_file != NULL) {
@@ -311,7 +311,7 @@ static int write_queue_record(struct udev_queue_export *udev_queue_export,
 write_error:
         /* if we failed half way through writing a record to a file,
            we should not try to write any further records to it. */
-        err(udev_queue_export->udev, "error writing to queue file: %m\n");
+        udev_err(udev_queue_export->udev, "error writing to queue file: %m\n");
         fclose(udev_queue_export->queue_file);
         udev_queue_export->queue_file = NULL;