chiark / gitweb /
vol_id: fix lib logging glue
[elogind.git] / extras / volume_id / vol_id.c
index d8302bc22923ede0a52d345107b5682a66a1955e..b47d6a4ecb1792819d2ba961542291c542cda3d2 100644 (file)
@@ -3,19 +3,18 @@
  *
  * Copyright (C) 2005-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.,
- *     675 Mass Ave, Cambridge, MA 02139, 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/>.
  */
 
 #ifndef _GNU_SOURCE
@@ -40,6 +39,7 @@
 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
 
 static int debug;
+struct udev *udev_ctx;
 
 static void log_fn(struct udev *udev, int priority,
                   const char *file, int line, const char *fn,
@@ -58,7 +58,7 @@ static void vid_log(int priority, const char *file, int line, const char *format
        va_list args;
 
        va_start(args, format);
-       log_fn(NULL, priority, file, line, NULL, format, args);
+       udev_log(udev_ctx, priority, file, line, NULL, format, args);
        va_end(args);
        return;
 }
@@ -110,7 +110,6 @@ static int all_probers(volume_id_probe_fn_t probe_fn,
 
 int main(int argc, char *argv[])
 {
-       struct udev *udev;
        static const struct option options[] = {
                { "label", 0, NULL, 'l' },
                { "label-raw", 0, NULL, 'L' },
@@ -147,11 +146,11 @@ int main(int argc, char *argv[])
        int retval;
        int rc = 0;
 
-       udev = udev_new();
-       if (udev == NULL)
+       udev_ctx = udev_new();
+       if (udev_ctx == NULL)
                goto exit;
        logging_init("vol_id");
-       udev_set_log_fn(udev, log_fn);
+       udev_set_log_fn(udev_ctx, log_fn);
 
        /* hook in our debug into libvolume_id */
        volume_id_log_fn = vid_log;
@@ -166,8 +165,8 @@ int main(int argc, char *argv[])
                switch (option) {
                case 'd':
                        debug = 1;
-                       if (udev_get_log_priority(udev) < LOG_INFO)
-                               udev_set_log_priority(udev, LOG_INFO);
+                       if (udev_get_log_priority(udev_ctx) < LOG_INFO)
+                               udev_set_log_priority(udev_ctx, LOG_INFO);
                        break;
                case 'l':
                        print = PRINT_LABEL;
@@ -215,7 +214,7 @@ int main(int argc, char *argv[])
 
        node = argv[optind];
        if (!node) {
-               err(udev, "no device\n");
+               err(udev_ctx, "no device\n");
                fprintf(stderr, "no device\n");
                rc = 1;
                goto exit;
@@ -236,7 +235,7 @@ int main(int argc, char *argv[])
 
        if (ioctl(fd, BLKGETSIZE64, &size) != 0)
                size = 0;
-       info(udev, "BLKGETSIZE64=%llu (%lluGB)\n", (unsigned long long)size, (unsigned long long)size >> 30);
+       info(udev_ctx, "BLKGETSIZE64=%llu (%lluGB)\n", (unsigned long long)size, (unsigned long long)size >> 30);
 
        /* try to drop all privileges before reading disk content */
        if (getuid() == 0) {
@@ -247,7 +246,7 @@ int main(int argc, char *argv[])
                        if (setgroups(0, NULL) != 0 ||
                            setgid(pw->pw_gid) != 0 ||
                            setuid(pw->pw_uid) != 0)
-                               info(udev, "unable to drop privileges: %s\n\n", strerror(errno));
+                               info(udev_ctx, "unable to drop privileges: %s\n\n", strerror(errno));
                }
        }
 
@@ -276,7 +275,7 @@ int main(int argc, char *argv[])
        }
 
        set_str(label_safe, label, sizeof(label_safe));
-       replace_chars(label_safe, ALLOWED_CHARS_INPUT);
+       util_replace_chars(label_safe, ALLOWED_CHARS_INPUT);
 
        volume_id_encode_string(label, label_enc, sizeof(label_enc));
        volume_id_encode_string(uuid, uuid_enc, sizeof(uuid_enc));
@@ -321,7 +320,7 @@ int main(int argc, char *argv[])
 exit:
        if (vid != NULL)
                volume_id_close(vid);
-       udev_unref(udev);
+       udev_unref(udev_ctx);
        logging_close();
        return rc;
 }