~ubuntu-branches/ubuntu/trusty/systemd/trusty

« back to all changes in this revision

Viewing changes to src/shared/install.c

Tags: upstream-202
ImportĀ upstreamĀ versionĀ 202

Show diffs side-by-side

added added

removed removed

Lines of Context:
198
198
                char** files) {
199
199
 
200
200
        int r = 0;
201
 
        DIR _cleanup_closedir_ *d = NULL;
 
201
        _cleanup_closedir_ DIR *d = NULL;
202
202
 
203
203
        assert(remove_symlinks_to);
204
204
        assert(fd >= 0);
235
235
 
236
236
                if (de->d_type == DT_DIR) {
237
237
                        int nfd, q;
238
 
                        char _cleanup_free_ *p = NULL;
 
238
                        _cleanup_free_ char *p = NULL;
239
239
 
240
240
                        nfd = openat(fd, de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
241
241
                        if (nfd < 0) {
260
260
                                r = q;
261
261
 
262
262
                } else if (de->d_type == DT_LNK) {
263
 
                        char _cleanup_free_ *p = NULL, *dest = NULL;
 
263
                        _cleanup_free_ char *p = NULL, *dest = NULL;
264
264
                        int q;
265
265
                        bool found;
266
266
 
362
362
                bool *same_name_link) {
363
363
 
364
364
        int r = 0;
365
 
        DIR _cleanup_closedir_ *d = NULL;
 
365
        _cleanup_closedir_ DIR *d = NULL;
366
366
 
367
367
        assert(name);
368
368
        assert(fd >= 0);
395
395
 
396
396
                if (de->d_type == DT_DIR) {
397
397
                        int nfd, q;
398
 
                        char _cleanup_free_ *p = NULL;
 
398
                        _cleanup_free_ char *p = NULL;
399
399
 
400
400
                        nfd = openat(fd, de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
401
401
                        if (nfd < 0) {
423
423
                                r = q;
424
424
 
425
425
                } else if (de->d_type == DT_LNK) {
426
 
                        char _cleanup_free_ *p = NULL, *dest = NULL;
 
426
                        _cleanup_free_ char *p = NULL, *dest = NULL;
427
427
                        bool found_path, found_dest, b = false;
428
428
                        int q;
429
429
 
458
458
                                found_dest = streq(path_get_file_name(dest), name);
459
459
 
460
460
                        if (found_path && found_dest) {
461
 
                                char _cleanup_free_ *t = NULL;
 
461
                                _cleanup_free_ char *t = NULL;
462
462
 
463
463
                                /* Filter out same name links in the main
464
464
                                 * config path */
508
508
                UnitFileState *state) {
509
509
 
510
510
        int r;
511
 
        char _cleanup_free_ *path = NULL;
 
511
        _cleanup_free_ char *path = NULL;
512
512
        bool same_name_link_runtime = false, same_name_link = false;
513
513
 
514
514
        assert(scope >= 0);
567
567
                unsigned *n_changes) {
568
568
 
569
569
        char **i;
570
 
        char _cleanup_free_ *prefix;
 
570
        _cleanup_free_ char *prefix;
571
571
        int r;
572
572
 
573
573
        assert(scope >= 0);
578
578
                return r;
579
579
 
580
580
        STRV_FOREACH(i, files) {
581
 
                char _cleanup_free_ *path = NULL;
 
581
                _cleanup_free_ char *path = NULL;
582
582
 
583
583
                if (!unit_name_is_valid(*i, true)) {
584
584
                        if (r == 0)
700
700
                UnitFileChange **changes,
701
701
                unsigned *n_changes) {
702
702
 
703
 
        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
 
703
        _cleanup_lookup_paths_free_ LookupPaths paths = {};
704
704
        char **i;
705
 
        char _cleanup_free_ *config_path = NULL;
 
705
        _cleanup_free_ char *config_path = NULL;
706
706
        int r, q;
707
707
 
708
708
        assert(scope >= 0);
717
717
                return r;
718
718
 
719
719
        STRV_FOREACH(i, files) {
720
 
                char _cleanup_free_ *path = NULL;
 
720
                _cleanup_free_ char *path = NULL;
721
721
                char *fn;
722
722
                struct stat st;
723
723
 
758
758
                }
759
759
 
760
760
                if (errno == EEXIST) {
761
 
                        char _cleanup_free_ *dest = NULL;
 
761
                        _cleanup_free_ char *dest = NULL;
762
762
 
763
763
                        q = readlink_and_make_absolute(path, &dest);
764
764
 
921
921
                return install_info_add(c, name_or_path, NULL);
922
922
}
923
923
 
924
 
static int config_parse_also(
925
 
                const char *filename,
926
 
                unsigned line,
927
 
                const char *section,
928
 
                const char *lvalue,
929
 
                int ltype,
930
 
                const char *rvalue,
931
 
                void *data,
932
 
                void *userdata) {
 
924
static int config_parse_also(const char *unit,
 
925
                             const char *filename,
 
926
                             unsigned line,
 
927
                             const char *section,
 
928
                             const char *lvalue,
 
929
                             int ltype,
 
930
                             const char *rvalue,
 
931
                             void *data,
 
932
                             void *userdata) {
933
933
 
934
934
        char *w;
935
935
        size_t l;
941
941
        assert(rvalue);
942
942
 
943
943
        FOREACH_WORD_QUOTED(w, l, rvalue, state) {
944
 
                char _cleanup_free_ *n;
 
944
                _cleanup_free_ char *n;
945
945
                int r;
946
946
 
947
947
                n = strndup(w, l);
956
956
        return 0;
957
957
}
958
958
 
959
 
static int config_parse_user(
960
 
                const char *filename,
961
 
                unsigned line,
962
 
                const char *section,
963
 
                const char *lvalue,
964
 
                int ltype,
965
 
                const char *rvalue,
966
 
                void *data,
967
 
                void *userdata) {
 
959
static int config_parse_user(const char *unit,
 
960
                             const char *filename,
 
961
                             unsigned line,
 
962
                             const char *section,
 
963
                             const char *lvalue,
 
964
                             int ltype,
 
965
                             const char *rvalue,
 
966
                             void *data,
 
967
                             void *userdata) {
968
968
 
969
969
        InstallInfo *i = data;
970
970
        char* printed;
999
999
        };
1000
1000
 
1001
1001
        int fd;
1002
 
        FILE _cleanup_fclose_ *f = NULL;
 
1002
        _cleanup_fclose_ FILE *f = NULL;
1003
1003
        int r;
1004
1004
 
1005
1005
        assert(c);
1016
1016
                return -ENOMEM;
1017
1017
        }
1018
1018
 
1019
 
        r = config_parse(path, f, NULL, config_item_table_lookup, (void*) items, true, info);
 
1019
        r = config_parse(NULL, path, f, NULL,
 
1020
                         config_item_table_lookup, (void*) items, true, info);
1020
1021
        if (r < 0)
1021
1022
                return r;
1022
1023
 
1116
1117
                const char *name,
1117
1118
                bool allow_symlink) {
1118
1119
 
1119
 
        InstallContext _cleanup_install_context_done_ c = {NULL};
 
1120
        _cleanup_install_context_done_ InstallContext c = {};
1120
1121
        InstallInfo *i;
1121
1122
        int r;
1122
1123
 
1147
1148
                UnitFileChange **changes,
1148
1149
                unsigned *n_changes) {
1149
1150
 
1150
 
        char _cleanup_free_ *dest = NULL;
 
1151
        _cleanup_free_ char *dest = NULL;
1151
1152
        int r;
1152
1153
 
1153
1154
        assert(old_path);
1198
1199
        assert(config_path);
1199
1200
 
1200
1201
        STRV_FOREACH(s, i->aliases) {
1201
 
                char _cleanup_free_ *alias_path = NULL, *dst = NULL;
 
1202
                _cleanup_free_ char *alias_path = NULL, *dst = NULL;
1202
1203
 
1203
1204
                dst = install_full_printf(i, *s);
1204
1205
                if (!dst)
1230
1231
        assert(config_path);
1231
1232
 
1232
1233
        STRV_FOREACH(s, i->wanted_by) {
1233
 
                char _cleanup_free_ *path = NULL, *dst = NULL;
 
1234
                _cleanup_free_ char *path = NULL, *dst = NULL;
1234
1235
 
1235
1236
                dst = install_full_printf(i, *s);
1236
1237
                if (!dst)
1267
1268
        assert(config_path);
1268
1269
 
1269
1270
        STRV_FOREACH(s, i->required_by) {
1270
 
                char _cleanup_free_ *path = NULL, *dst = NULL;
 
1271
                _cleanup_free_ char *path = NULL, *dst = NULL;
1271
1272
 
1272
1273
                dst = install_full_printf(i, *s);
1273
1274
                if (!dst)
1299
1300
                unsigned *n_changes) {
1300
1301
 
1301
1302
        int r;
1302
 
        char _cleanup_free_ *path = NULL;
 
1303
        _cleanup_free_ char *path = NULL;
1303
1304
 
1304
1305
        assert(i);
1305
1306
        assert(paths);
1452
1453
                UnitFileChange **changes,
1453
1454
                unsigned *n_changes) {
1454
1455
 
1455
 
        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
1456
 
        InstallContext _cleanup_install_context_done_ c = {NULL};
 
1456
        _cleanup_lookup_paths_free_ LookupPaths paths = {};
 
1457
        _cleanup_install_context_done_ InstallContext c = {};
1457
1458
        char **i;
1458
 
        char _cleanup_free_ *config_path = NULL;
 
1459
        _cleanup_free_ char *config_path = NULL;
1459
1460
        int r;
1460
1461
 
1461
1462
        assert(scope >= 0);
1491
1492
                UnitFileChange **changes,
1492
1493
                unsigned *n_changes) {
1493
1494
 
1494
 
        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
1495
 
        InstallContext _cleanup_install_context_done_ c = {NULL};
 
1495
        _cleanup_lookup_paths_free_ LookupPaths paths = {};
 
1496
        _cleanup_install_context_done_ InstallContext c = {};
1496
1497
        char **i;
1497
 
        char _cleanup_free_ *config_path = NULL;
1498
 
        Set _cleanup_set_free_free_ *remove_symlinks_to = NULL;
 
1498
        _cleanup_free_ char *config_path = NULL;
 
1499
        _cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
1499
1500
        int r, q;
1500
1501
 
1501
1502
        assert(scope >= 0);
1533
1534
                UnitFileChange **changes,
1534
1535
                unsigned *n_changes) {
1535
1536
 
1536
 
        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
1537
 
        InstallContext _cleanup_install_context_done_ c = {NULL};
 
1537
        _cleanup_lookup_paths_free_ LookupPaths paths = {};
 
1538
        _cleanup_install_context_done_ InstallContext c = {};
1538
1539
        char **i;
1539
 
        char _cleanup_free_ *config_path = NULL;
1540
 
        Set _cleanup_set_free_free_ *remove_symlinks_to = NULL;
 
1540
        _cleanup_free_ char *config_path = NULL;
 
1541
        _cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
1541
1542
        int r, q;
1542
1543
 
1543
1544
        assert(scope >= 0);
1576
1577
                const char *root_dir,
1577
1578
                const char *name) {
1578
1579
 
1579
 
        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
 
1580
        _cleanup_lookup_paths_free_ LookupPaths paths = {};
1580
1581
        UnitFileState state = _UNIT_FILE_STATE_INVALID;
1581
1582
        char **i;
1582
 
        char _cleanup_free_ *path = NULL;
 
1583
        _cleanup_free_ char *path = NULL;
1583
1584
        int r;
1584
1585
 
1585
1586
        assert(scope >= 0);
1637
1638
                        return state;
1638
1639
 
1639
1640
                r = unit_file_can_install(&paths, root_dir, path, true);
1640
 
                if (r < 0 && errno != -ENOENT)
 
1641
                if (r < 0 && errno != ENOENT)
1641
1642
                        return r;
1642
1643
                else if (r > 0)
1643
1644
                        return UNIT_FILE_DISABLED;
1649
1650
}
1650
1651
 
1651
1652
int unit_file_query_preset(UnitFileScope scope, const char *name) {
1652
 
        char _cleanup_strv_free_ **files = NULL;
 
1653
        _cleanup_strv_free_ char **files = NULL;
1653
1654
        char **i;
1654
1655
        int r;
1655
1656
 
1679
1680
                return r;
1680
1681
 
1681
1682
        STRV_FOREACH(i, files) {
1682
 
                FILE _cleanup_fclose_ *f;
 
1683
                _cleanup_fclose_ FILE *f;
1683
1684
 
1684
1685
                f = fopen(*i, "re");
1685
1686
                if (!f) {
1699
1700
                        if (!*l)
1700
1701
                                continue;
1701
1702
 
1702
 
                        if (strchr(COMMENTS, *l))
 
1703
                        if (strchr(COMMENTS "\n", *l))
1703
1704
                                continue;
1704
1705
 
1705
1706
                        if (first_word(l, "enable")) {
1734
1735
                UnitFileChange **changes,
1735
1736
                unsigned *n_changes) {
1736
1737
 
1737
 
        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
1738
 
        InstallContext _cleanup_install_context_done_ plus = {NULL}, minus = {NULL};
 
1738
        _cleanup_lookup_paths_free_ LookupPaths paths = {};
 
1739
        _cleanup_install_context_done_ InstallContext plus = {}, minus = {};
1739
1740
        char **i;
1740
 
        char _cleanup_free_ *config_path = NULL;
1741
 
        Set _cleanup_set_free_free_ *remove_symlinks_to = NULL;
 
1741
        _cleanup_free_ char *config_path = NULL;
 
1742
        _cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
1742
1743
        int r, q;
1743
1744
 
1744
1745
        assert(scope >= 0);
1800
1801
                const char *root_dir,
1801
1802
                Hashmap *h) {
1802
1803
 
1803
 
        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
 
1804
        _cleanup_lookup_paths_free_ LookupPaths paths = {};
1804
1805
        char **i;
1805
 
        char _cleanup_free_ *buf = NULL;
1806
 
        DIR _cleanup_closedir_ *d = NULL;
 
1806
        _cleanup_free_ char *buf = NULL;
 
1807
        _cleanup_closedir_ DIR *d = NULL;
1807
1808
        int r;
1808
1809
 
1809
1810
        assert(scope >= 0);