~ubuntu-branches/ubuntu/oneiric/udev/oneiric-proposed

« back to all changes in this revision

Viewing changes to extras/path_id/path_id.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-07-11 15:28:25 UTC
  • mfrom: (0.7.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20110711152825-7tompjwuzr1aljjf
Tags: 172-0ubuntu1
* New upstream release:
  - Now enables kenrel media polling if available. This goes together with
    the changes in udisks 1.0.3 to stop user-space polling if kernel polling
    is enabled.
  - Delete mobile-action-modeswitch, has been deprecated by usb-modeswitch
    for a long time now.
* debian/rules: Fix build tree copying to cope with new upstream
  "build-aux/" directory.
* debian/libudev0.symbols: Add new symbols for this release.
* debian/control: Add gir1.2-gudev-1.0 dependency to libgudev-1.0-dev, as
  per current Debian GI policy.
* debian/control: Wrap dependencies.
* debian/control: Add versioned libudev0 dependency to udev. While udevd or
  the probers do not directly link to it (they have an internal copy), they
  still need to be in sync to work properly. (LP: #804577)

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
static int path_prepend(char **path, const char *fmt, ...)
51
51
{
52
52
        va_list va;
53
 
        char *old;
54
53
        char *pre;
55
 
        int err;
56
 
 
57
 
        old = *path;
 
54
        int err = 0;
58
55
 
59
56
        va_start(va, fmt);
60
57
        err = vasprintf(&pre, fmt, va);
61
58
        va_end(va);
62
59
        if (err < 0)
63
 
                return err;
64
 
 
65
 
        if (old != NULL) {
66
 
                err = asprintf(path, "%s-%s", pre, old);
 
60
                goto out;
 
61
 
 
62
        if (*path != NULL) {
 
63
                char *new;
 
64
 
 
65
                err = asprintf(&new, "%s-%s", pre, *path);
 
66
                free(pre);
67
67
                if (err < 0)
68
 
                        return err;
69
 
                free(pre);
 
68
                        goto out;
 
69
                free(*path);
 
70
                *path = new;
70
71
        } else {
71
72
                *path = pre;
72
73
        }
73
 
 
74
 
        free(old);
75
 
        return 0;
 
74
out:
 
75
        return err;
76
76
}
77
77
 
78
78
/*
337
337
        return parent;
338
338
}
339
339
 
340
 
static void handle_scsi_tape(struct udev_device *dev, char **suffix)
 
340
static void handle_scsi_tape(struct udev_device *dev, char **path)
341
341
{
342
342
        const char *name;
343
343
 
 
344
        /* must be the last device in the syspath */
 
345
        if (*path != NULL)
 
346
                return;
 
347
 
344
348
        name = udev_device_get_sysname(dev);
345
349
        if (strncmp(name, "nst", 3) == 0 && strchr("lma", name[3]) != NULL)
346
 
                asprintf(suffix, "nst%c", name[3]);
 
350
                path_prepend(path, "nst%c", name[3]);
347
351
        else if (strncmp(name, "st", 2) == 0 && strchr("lma", name[2]) != NULL)
348
 
                asprintf(suffix, "st%c", name[2]);
 
352
                path_prepend(path, "st%c", name[2]);
349
353
}
350
354
 
351
355
static struct udev_device *handle_usb(struct udev_device *parent, char **path)
413
417
        struct udev_device *parent;
414
418
        char syspath[UTIL_PATH_SIZE];
415
419
        const char *devpath;
416
 
        char *path;
417
 
        char *path_suffix;
418
 
        int rc = 1;
 
420
        char *path = NULL;
 
421
        int rc = EXIT_FAILURE;
419
422
 
420
423
        udev = udev_new();
421
424
        if (udev == NULL)
460
463
                goto exit;
461
464
        }
462
465
 
463
 
        path = NULL;
464
 
        path_suffix = NULL;
465
 
 
466
466
        /* S390 ccw bus */
467
467
        parent = udev_device_get_parent_with_subsystem_devtype(dev, "ccw", NULL);
468
468
        if (parent != NULL) {
480
480
                if (subsys == NULL) {
481
481
                        ;
482
482
                } else if (strcmp(subsys, "scsi_tape") == 0) {
483
 
                        handle_scsi_tape(parent, &path_suffix);
 
483
                        handle_scsi_tape(parent, &path);
484
484
                } else if (strcmp(subsys, "scsi") == 0) {
485
485
                        parent = handle_scsi(parent, &path);
486
486
                } else if (strcmp(subsys, "cciss") == 0) {
496
496
                } else if (strcmp(subsys, "platform") == 0) {
497
497
                        path_prepend(&path, "platform-%s", udev_device_get_sysname(parent));
498
498
                        parent = skip_subsystem(parent, "platform");
 
499
                } else if (strcmp(subsys, "acpi") == 0) {
 
500
                        path_prepend(&path, "acpi-%s", udev_device_get_sysname(parent));
 
501
                        parent = skip_subsystem(parent, "acpi");
499
502
                } else if (strcmp(subsys, "xen") == 0) {
500
503
                        path_prepend(&path, "xen-%s", udev_device_get_sysname(parent));
501
504
                        parent = skip_subsystem(parent, "xen");
508
511
        }
509
512
out:
510
513
        if (path != NULL) {
511
 
                if (path_suffix != NULL) {
512
 
                        printf("ID_PATH=%s%s\n", path, path_suffix);
513
 
                        free(path_suffix);
514
 
                } else {
515
 
                        printf("ID_PATH=%s\n", path);
 
514
                char tag[UTIL_NAME_SIZE];
 
515
                size_t i;
 
516
                const char *p;
 
517
 
 
518
                /* compose valid udev tag name */
 
519
                for (p = path, i = 0; *p; p++) {
 
520
                        if ((*p >= '0' && *p <= '9') ||
 
521
                            (*p >= 'A' && *p <= 'Z') ||
 
522
                            (*p >= 'a' && *p <= 'z') ||
 
523
                            *p == '-') {
 
524
                                tag[i++] = *p;
 
525
                                continue;
 
526
                        }
 
527
 
 
528
                        /* skip all leading '_' */
 
529
                        if (i == 0)
 
530
                                continue;
 
531
 
 
532
                        /* avoid second '_' */
 
533
                        if (tag[i-1] == '_')
 
534
                                continue;
 
535
 
 
536
                        tag[i++] = '_';
516
537
                }
 
538
                /* strip trailing '_' */
 
539
                while (i > 0 && tag[i-1] == '_')
 
540
                        i--;
 
541
                tag[i] = '\0';
 
542
 
 
543
                printf("ID_PATH=%s\n", path);
 
544
                printf("ID_PATH_TAG=%s\n", tag);
517
545
                free(path);
518
 
                rc = 0;
 
546
                rc = EXIT_SUCCESS;
519
547
        }
520
548
 
521
549
        udev_device_unref(dev);