Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 617580
Collapse All | Expand All

(-)a/Makefile (-6 / +21 lines)
Lines 1-12 Link Here
1
EPREFIX ?=
1
binprogs = tmpfiles
2
binprogs = tmpfiles
2
bindir = /bin
3
bindir = $(EPREFIX)/bin
3
binmode = 0755
4
binmode = 0755
4
install = install
5
install = install
5
6
6
all:
7
SOURCES = $(binprogs)
7
8
8
install:
9
all: $(SOURCES)
9
	$(install) -d $(DESTDIR)$(bindir)
10
	$(install) -m $(binmode) $(binprogs) $(DESTDIR)$(bindir)
11
10
12
.PHONY: all install
11
install: $(SOURCES)
12
	$(install) -d "$(DESTDIR)$(bindir)"
13
	$(install) -m $(binmode) $(binprogs) "$(DESTDIR)$(bindir)"
14
15
clean:
16
17
distclean:
18
	rm -f $(SOURCES)
19
20
.PHONY: all install clean distclean
21
22
$(SOURCES): Makefile
23
24
%: %.in
25
	sed -e \
26
		's^@EPREFIX@^$(EPREFIX)^g' \
27
	> $@ < $<
(-)a/tmpfiles (-66 / +77 lines)
Lines 16-21 Link Here
16
# as of 2012/03/12 and also implements some more recent features
16
# as of 2012/03/12 and also implements some more recent features
17
#
17
#
18
18
19
EPREFIX="@EPREFIX@"
19
DRYRUN=0
20
DRYRUN=0
20
21
21
checkprefix() {
22
checkprefix() {
Lines 55-61 _chattr() { Link Here
55
		*) attr="+$attr" ;;
56
		*) attr="+$attr" ;;
56
	esac
57
	esac
57
	local IFS=
58
	local IFS=
58
	dryrun_or_real chattr $1 "$attr" -- $3
59
	dryrun_or_real chattr $1 "$attr" -- "$EPREFIX$3"
59
}
60
}
60
61
61
relabel() {
62
relabel() {
Lines 65-94 relabel() { Link Here
65
66
66
	status=0
67
	status=0
67
	for path in ${paths}; do
68
	for path in ${paths}; do
68
		if [ -e "$path" ]; then
69
		if [ -e "$EPREFIX$path" ]; then
69
			if [ -x /sbin/restorecon ]; then
70
			if [ -x "$EPREFIX"/sbin/restorecon ]; then
70
				dryrun_or_real restorecon $CHOPTS "$path"
71
				dryrun_or_real "$EPREFIX"/sbin/restorecon $CHOPTS "$EPREFIX$path"
71
				x=$?
72
				x=$?
72
				if [ $x -ne 0 ]; then
73
				if [ $x -ne 0 ]; then
73
					status=$x
74
					status=$x
74
				fi
75
				fi
75
			fi
76
			fi
76
			if [ $uid != '-' ]; then
77
			if [ $uid != '-' ]; then
77
				dryrun_or_real chown $CHOPTS "$uid" "$path"
78
				dryrun_or_real chown $CHOPTS "$uid" "$EPREFIX$path"
78
				x=$?
79
				x=$?
79
				if [ $x -ne 0 ]; then
80
				if [ $x -ne 0 ]; then
80
					status=$x
81
					status=$x
81
				fi
82
				fi
82
			fi
83
			fi
83
			if [ $gid != '-' ]; then
84
			if [ $gid != '-' ]; then
84
				dryrun_or_real chgrp $CHOPTS "$gid" "$path"
85
				dryrun_or_real chgrp $CHOPTS "$gid" "$EPREFIX$path"
85
				x=$?
86
				x=$?
86
				if [ $x -ne 0 ]; then
87
				if [ $x -ne 0 ]; then
87
					status=$x
88
					status=$x
88
				fi
89
				fi
89
			fi
90
			fi
90
			if [ $mode != '-' ]; then
91
			if [ $mode != '-' ]; then
91
				dryrun_or_real chmod $CHOPTS "$mode" "$path"
92
				dryrun_or_real chmod $CHOPTS "$mode" "$EPREFIX$path"
92
				x=$?
93
				x=$?
93
				if [ $x -ne 0 ]; then
94
				if [ $x -ne 0 ]; then
94
					status=$x
95
					status=$x
Lines 99-122 relabel() { Link Here
99
	return $status
100
	return $status
100
}
101
}
101
102
102
splitpath() {
103
splitpath_quoted() {
103
    local path=$1
104
    local path=$1 EPREFIX=$2
104
    while [ -n "$path" ]; do
105
    while [ -n "$path" ]; do
105
        echo $path
106
        echo "\'$EPREFIX$path\'"
106
        path=${path%/*}
107
        path=${path%/*}
107
    done
108
    done
108
}
109
}
109
110
110
_restorecon() {
111
_restorecon() {
111
    local path=$1
112
    local path=$1 p
112
    if [ -x /sbin/restorecon ]; then
113
    if [ -x "$EPREFIX"/sbin/restorecon ]; then
113
        dryrun_or_real restorecon -F $(splitpath "$path")
114
        eval "dryrun_or_real '$EPREFIX/sbin/restorecon' -F $(splitpath_quoted "$path" "$EPREFIX")"
114
    fi
115
    fi
115
}
116
}
116
117
117
createdirectory() {
118
createdirectory() {
118
	local mode="$1" uid="$2" gid="$3" path="$4"
119
	local mode="$1" uid="$2" gid="$3" path="$4"
119
	dryrun_or_real mkdir -p "$path"
120
	dryrun_or_real mkdir -p "$EPREFIX$path"
120
	if [ "$uid" = - ]; then
121
	if [ "$uid" = - ]; then
121
		uid=root
122
		uid=root
122
	fi
123
	fi
Lines 126-139 createdirectory() { Link Here
126
	if [ "$mode" = - ]; then
127
	if [ "$mode" = - ]; then
127
		mode=0755
128
		mode=0755
128
	fi
129
	fi
129
	dryrun_or_real chown $uid "$path"
130
	dryrun_or_real chown $uid "$EPREFIX$path"
130
	dryrun_or_real chgrp $gid "$path"
131
	dryrun_or_real chgrp $gid "$EPREFIX$path"
131
	dryrun_or_real chmod $mode "$path"
132
	dryrun_or_real chmod $mode "$EPREFIX$path"
132
}
133
}
133
134
134
createfile() {
135
createfile() {
135
	local mode="$1" uid="$2" gid="$3" path="$4"
136
	local mode="$1" uid="$2" gid="$3" path="$4"
136
	dryrun_or_real touch "$path"
137
	dryrun_or_real touch "$EPREFIX$path"
137
	if [ "$uid" = - ]; then
138
	if [ "$uid" = - ]; then
138
		uid=root
139
		uid=root
139
	fi
140
	fi
Lines 143-156 createfile() { Link Here
143
	if [ "$mode" = - ]; then
144
	if [ "$mode" = - ]; then
144
		mode=0644
145
		mode=0644
145
	fi
146
	fi
146
	dryrun_or_real chown $uid "$path"
147
	dryrun_or_real chown $uid "$EPREFIX$path"
147
	dryrun_or_real chgrp $gid "$path"
148
	dryrun_or_real chgrp $gid "$EPREFIX$path"
148
	dryrun_or_real chmod $mode "$path"
149
	dryrun_or_real chmod $mode "$EPREFIX$path"
149
}
150
}
150
151
151
createpipe() {
152
createpipe() {
152
	local mode="$1" uid="$2" gid="$3" path="$4"
153
	local mode="$1" uid="$2" gid="$3" path="$4"
153
	dryrun_or_real mkfifo "$path"
154
	dryrun_or_real mkfifo "$EPREFIX$path"
154
	if [ "$uid" = - ]; then
155
	if [ "$uid" = - ]; then
155
		uid=root
156
		uid=root
156
	fi
157
	fi
Lines 160-168 createpipe() { Link Here
160
	if [ "$mode" = - ]; then
161
	if [ "$mode" = - ]; then
161
		mode=0644
162
		mode=0644
162
	fi
163
	fi
163
	dryrun_or_real chown $uid "$path"
164
	dryrun_or_real chown $uid "$EPREFIX$path"
164
	dryrun_or_real chgrp $gid "$path"
165
	dryrun_or_real chgrp $gid "$EPREFIX$path"
165
	dryrun_or_real chmod $mode "$path"
166
	dryrun_or_real chmod $mode "$EPREFIX$path"
166
}
167
}
167
168
168
_b() {
169
_b() {
Lines 177-187 _b() { Link Here
177
	if [ "$mode" = - ]; then
178
	if [ "$mode" = - ]; then
178
		mode=0644
179
		mode=0644
179
	fi
180
	fi
180
	if [ ! -e "$path" ]; then
181
	if [ ! -e "$EPREFIX$path" ]; then
181
		dryrun_or_real mknod -m $mode $path b ${arg%:*} ${arg#*:}
182
		dryrun_or_real mknod -m $mode "$EPREFIX$path" b ${arg%:*} ${arg#*:}
182
		_restorecon "$path"
183
		_restorecon "$path"
183
		dryrun_or_real chown $uid "$path"
184
		dryrun_or_real chown $uid "$EPREFIX$path"
184
		dryrun_or_real chgrp $gid "$path"
185
		dryrun_or_real chgrp $gid "$EPREFIX$path"
185
	fi
186
	fi
186
}
187
}
187
188
Lines 197-224 _c() { Link Here
197
	if [ "$mode" = - ]; then
198
	if [ "$mode" = - ]; then
198
		mode=0644
199
		mode=0644
199
	fi
200
	fi
200
	if [ ! -e "$path" ]; then
201
	if [ ! -e "$EPREFIX$path" ]; then
201
		dryrun_or_real mknod -m $mode $path c ${arg%:*} ${arg#*:}
202
		dryrun_or_real mknod -m $mode "$EPREFIX$path" c ${arg%:*} ${arg#*:}
202
		_restorecon "$path"
203
		_restorecon "$path"
203
		dryrun_or_real chown $uid "$path"
204
		dryrun_or_real chown $uid "$EPREFIX$path"
204
		dryrun_or_real chgrp $gid "$path"
205
		dryrun_or_real chgrp $gid "$EPREFIX$path"
205
	fi
206
	fi
206
}
207
}
207
208
208
_C() {
209
_C() {
209
	# recursively copy a file or directory
210
	# recursively copy a file or directory
210
	local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
211
	local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
211
	if [ ! -e "$path" ]; then
212
	if [ ! -e "$EPREFIX$path" ]; then
212
		dryrun_or_real cp -r "$arg" "$path"
213
		dryrun_or_real cp -r "$arg" "$EPREFIX$path"
213
		_restorecon "$path"
214
		_restorecon "$path"
214
		if [ $uid != '-' ]; then
215
		if [ $uid != '-' ]; then
215
			dryrun_or_real chown "$uid" "$path"
216
			dryrun_or_real chown "$uid" "$EPREFIX$path"
216
		fi
217
		fi
217
		if [ $gid != '-' ]; then
218
		if [ $gid != '-' ]; then
218
			dryrun_or_real chgrp "$gid" "$path"
219
			dryrun_or_real chgrp "$gid" "$EPREFIX$path"
219
		fi
220
		fi
220
		if [ $mode != '-']; then
221
		if [ $mode != '-']; then
221
			dryrun_or_real chmod "$mode" "$path"
222
			dryrun_or_real chmod "$mode" "$EPREFIX$path"
222
		fi
223
		fi
223
	fi
224
	fi
224
}
225
}
Lines 229-235 _f() { Link Here
229
230
230
	[ $CREATE -gt 0 ] || return 0
231
	[ $CREATE -gt 0 ] || return 0
231
232
232
	if [ ! -e "$path" ]; then
233
	if [ ! -e "$EPREFIX$path" ]; then
233
		createfile "$mode" "$uid" "$gid" "$path"
234
		createfile "$mode" "$uid" "$gid" "$path"
234
		if [ -n "$arg" ]; then
235
		if [ -n "$arg" ]; then
235
			_w "$@"
236
			_w "$@"
Lines 243-249 _F() { Link Here
243
244
244
	[ $CREATE -gt 0 ] || return 0
245
	[ $CREATE -gt 0 ] || return 0
245
246
246
	dryrun_or_real rm -f "$path"
247
	dryrun_or_real rm -f "$EPREFIX$path"
247
	createfile "$mode" "$uid" "$gid" "$path"
248
	createfile "$mode" "$uid" "$gid" "$path"
248
	if [ -n "$arg" ]; then
249
	if [ -n "$arg" ]; then
249
		_w "$@"
250
		_w "$@"
Lines 256-262 _d() { Link Here
256
257
257
	[ $CREATE -gt 0 ] || return 0
258
	[ $CREATE -gt 0 ] || return 0
258
259
259
	if [ ! -d "$path" ]; then
260
	if [ ! -d "$EPREFIX$path" ]; then
260
		createdirectory "$mode" "$uid" "$gid" "$path"
261
		createdirectory "$mode" "$uid" "$gid" "$path"
261
		_restorecon "$path"
262
		_restorecon "$path"
262
	fi
263
	fi
Lines 266-273 _D() { Link Here
266
	# Create or empty a directory
267
	# Create or empty a directory
267
	local path=$1 mode=$2 uid=$3 gid=$4
268
	local path=$1 mode=$2 uid=$3 gid=$4
268
269
269
	if [ -d "$path" ] && [ $REMOVE -gt 0 ]; then
270
	if [ -d "$EPREFIX$path" ] && [ $REMOVE -gt 0 ]; then
270
		dryrun_or_real find "$path" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
271
		dryrun_or_real find "$EPREFIX$path" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
271
		_restorecon "$path"
272
		_restorecon "$path"
272
	fi
273
	fi
273
274
Lines 318-325 _H() { Link Here
318
_L() {
319
_L() {
319
	# Create a symlink if it doesn't exist yet
320
	# Create a symlink if it doesn't exist yet
320
	local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
321
	local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
321
	if [ ! -e "$path" ]; then
322
	if [ ! -e "$EPREFIX$path" ]; then
322
		dryrun_or_real ln -s "$arg" "$path"
323
		dryrun_or_real ln -s "$arg" "$EPREFIX$path"
323
	fi
324
	fi
324
	_restorecon "$path"
325
	_restorecon "$path"
325
}
326
}
Lines 330-336 _p() { Link Here
330
331
331
	[ $CREATE -gt 0 ] || return 0
332
	[ $CREATE -gt 0 ] || return 0
332
333
333
	if [ ! -p "$path" ]; then
334
	if [ ! -p "$EPREFIX$path" ]; then
334
		createpipe "$mode" "$uid" "$gid" "$path"
335
		createpipe "$mode" "$uid" "$gid" "$path"
335
	fi
336
	fi
336
}
337
}
Lines 366-375 _r() { Link Here
366
367
367
	status=0
368
	status=0
368
	for path in ${paths}; do
369
	for path in ${paths}; do
369
		if [ -f "$path" ]; then
370
		if [ -f "$EPREFIX$path" ]; then
370
			dryrun_or_real rm -f "$path"
371
			dryrun_or_real rm -f "$EPREFIX$path"
371
		elif [ -d "$path" ]; then
372
		elif [ -d "$EPREFIX$path" ]; then
372
			dryrun_or_real rmdir "$path"
373
			dryrun_or_real rmdir "$EPREFIX$path"
373
		fi
374
		fi
374
		x=$?
375
		x=$?
375
		if [ $x -ne 0 ]; then
376
		if [ $x -ne 0 ]; then
Lines 390-397 _R() { Link Here
390
391
391
	status=0
392
	status=0
392
	for path in ${paths}; do
393
	for path in ${paths}; do
393
		if [ -d "$path" ]; then
394
		if [ -d "$EPREFIX$path" ]; then
394
			dryrun_or_real rm -rf --one-file-system "$path"
395
			dryrun_or_real rm -rf --one-file-system "$EPREFIX$path"
395
			x=$?
396
			x=$?
396
			if [ $x -ne 0 ]; then
397
			if [ $x -ne 0 ]; then
397
				status=$x
398
				status=$x
Lines 404-414 _R() { Link Here
404
_w() {
405
_w() {
405
	# Write the argument parameter to a file, if it exists.
406
	# Write the argument parameter to a file, if it exists.
406
	local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
407
	local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
407
	if [ -f "$path" ]; then
408
	if [ -f "$EPREFIX$path" ]; then
408
		if [ $DRYRUN -eq 1 ]; then
409
		if [ $DRYRUN -eq 1 ]; then
409
			echo "echo \"$arg\" >>\"$path\""
410
			echo "echo \"$arg\" >>\"$EPREFIX$path\""
410
		else
411
		else
411
			echo "$arg" >>"$path"
412
			echo "$arg" >>"$EPREFIX$path"
412
		fi
413
		fi
413
	fi
414
	fi
414
}
415
}
Lines 437-442 PREFIX= Link Here
437
FILES=
438
FILES=
438
439
439
while [ $# -gt 0 ]; do
440
while [ $# -gt 0 ]; do
441
	# File system (*-prefix=) arguments do not need to contain the EPREFIX,
442
	# we will stick them to within the EPREFIX anyway.
440
	case $1 in
443
	case $1 in
441
		--boot) BOOT=1 ;;
444
		--boot) BOOT=1 ;;
442
		--create) CREATE=1 ;;
445
		--create) CREATE=1 ;;
Lines 444-453 while [ $# -gt 0 ]; do Link Here
444
		--clean) CLEAN=1 ;; # TODO: Not implemented
447
		--clean) CLEAN=1 ;; # TODO: Not implemented
445
		--verbose) VERBOSE=1 ;;
448
		--verbose) VERBOSE=1 ;;
446
		--dryrun|--dry-run) DRYRUN=1 ;;
449
		--dryrun|--dry-run) DRYRUN=1 ;;
447
		--exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} " ;;
450
		--exclude-prefix=*) arg=${1##--exclude-prefix=}; EXCLUDE="${EXCLUDE}${arg#$EPREFIX} " ;;
448
		--prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;;
451
		--prefix=*) arg=${1##--prefix=}; PREFIX="${PREFIX}${arg#$EPREFIX} " ;;
449
		-*) invalid_option "$1" ;;
452
		-*) invalid_option "$1" ;;
450
		*) FILES="${FILES} $1"
453
		*) FILES="${FILES} ${1#$EPREFIX}"
451
	esac
454
	esac
452
	shift
455
	shift
453
done
456
done
Lines 473-483 if [ -z "${FILES}" ]; then Link Here
473
	# `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
476
	# `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
474
	# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
477
	# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
475
	for d in ${tmpfiles_dirs} ; do
478
	for d in ${tmpfiles_dirs} ; do
476
		[ -d $d ] && for f in ${d}/*.conf ; do
479
		[ -d "$EPREFIX"$d ] && for f in "$EPREFIX"${d}/*.conf ; do
477
			case "${f##*/}" in
480
			case "${f##*/}" in
478
				systemd.conf|systemd-*.conf) continue;;
481
				systemd.conf|systemd-*.conf) continue;;
479
			esac
482
			esac
480
			[ -f $f ] && tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
483
			[ -f "$f" ] && tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
481
		done # for f in ${d}
484
		done # for f in ${d}
482
	done # for d in ${tmpfiles_dirs}
485
	done # for d in ${tmpfiles_dirs}
483
	FILES="$(printf "${tmpfiles_basenames}\n" | sort -u )"
486
	FILES="$(printf "${tmpfiles_basenames}\n" | sort -u )"
Lines 488-502 tmpfiles_d='' Link Here
488
for b in ${FILES} ; do
491
for b in ${FILES} ; do
489
	if [ "${b##*/}" != "${b}" ]; then
492
	if [ "${b##*/}" != "${b}" ]; then
490
		# The user specified a path on the command line
493
		# The user specified a path on the command line
491
		# Just pass it through unaltered
494
		# Just pass it through unaltered (without the optional EPREFIX)
492
		tmpfiles_d="${tmpfiles_d} ${b}"
495
		tmpfiles_d="${tmpfiles_d} ${b#$EPREFIX}"
493
	else
496
	else
494
		real_f=''
497
		real_f=''
495
		for d in $tmpfiles_dirs ; do
498
		for d in $tmpfiles_dirs ; do
499
			d=$d
496
			f=${d}/${b}
500
			f=${d}/${b}
497
			[ -f "${f}" ] && real_f=$f
501
			[ -f "$EPREFIX${f}" ] && real_f=$f
498
		done
502
		done
499
		[ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
503
		[ -f "$EPREFIX${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
500
	fi
504
	fi
501
done
505
done
502
506
Lines 515-520 for FILE in $tmpfiles_d ; do Link Here
515
	# d    /run/user      0755 root root 10d -
519
	# d    /run/user      0755 root root 10d -
516
	# Mode, UID, GID, Age, Argument may be omitted!
520
	# Mode, UID, GID, Age, Argument may be omitted!
517
	# If Cmd ends with !, the line is only processed if --boot is passed
521
	# If Cmd ends with !, the line is only processed if --boot is passed
522
	# Path must not contain the EPREFIX, it is prepended within EPREFIX.
523
	# However, Argument must contain the EPREFIX if appropriate.
518
524
519
	# XXX: Upstream says whitespace is NOT permitted in the Path argument.
525
	# XXX: Upstream says whitespace is NOT permitted in the Path argument.
520
	# But IS allowed when globs are expanded for the x/r/R/z/Z types.
526
	# But IS allowed when globs are expanded for the x/r/R/z/Z types.
Lines 531-536 for FILE in $tmpfiles_d ; do Link Here
531
			\#*) continue ;;
537
			\#*) continue ;;
532
		esac
538
		esac
533
539
540
		# Reject Path with EPREFIX, we fail to parse blanks anyway.
541
		# For Argument, as the last one parsed, blanks should work.
542
		if [ "${path#$EPREFIX}" != $path ]; then
543
			warninvalid ; continue
544
		fi
545
534
		while [ ${#cmd} -gt 1 ]; do
546
		while [ ${#cmd} -gt 1 ]; do
535
			case $cmd in
547
			case $cmd in
536
				*!) cmd=${cmd%!}; [ "$BOOT" -eq "1" ] || continue 2 ;;
548
				*!) cmd=${cmd%!}; [ "$BOOT" -eq "1" ] || continue 2 ;;
Lines 575-581 for FILE in $tmpfiles_d ; do Link Here
575
		if [ "${DRYRUN}" -eq "0" ]; then
587
		if [ "${DRYRUN}" -eq "0" ]; then
576
			[ $rc -ne 0 ] && error=$((error + 1))
588
			[ $rc -ne 0 ] && error=$((error + 1))
577
		fi
589
		fi
578
	done <$FILE
590
	done <"$EPREFIX"$FILE
579
done
591
done
580
592
581
exit $error
593
exit $error
582
- 

Return to bug 617580