40
40
#define _GNU_SOURCE /* TEMP_FAILURE_RETRY(), asprintf() */
42
42
#include <stdio.h> /* fprintf(), stderr, fwrite(),
43
stdout, ferror(), remove() */
44
44
#include <stdint.h> /* uint16_t, uint32_t, intptr_t */
45
45
#include <stddef.h> /* NULL, size_t, ssize_t */
46
46
#include <stdlib.h> /* free(), EXIT_SUCCESS, srand(),
57
57
#include <sys/socket.h> /* socket(), struct sockaddr_in6,
58
58
inet_pton(), connect(),
60
#include <fcntl.h> /* open() */
60
#include <fcntl.h> /* open(), unlinkat() */
61
61
#include <dirent.h> /* opendir(), struct dirent, readdir()
63
63
#include <inttypes.h> /* PRIu16, PRIdMAX, intmax_t,
74
74
#include <unistd.h> /* close(), SEEK_SET, off_t, write(),
75
75
getuid(), getgid(), seteuid(),
76
setgid(), pause(), _exit() */
76
setgid(), pause(), _exit(),
77
78
#include <arpa/inet.h> /* inet_pton(), htons() */
78
79
#include <iso646.h> /* not, or, and */
79
80
#include <argp.h> /* struct argp_option, error_t, struct
2617
2618
/* Removes the GPGME temp directory and all files inside */
2618
2619
if(tempdir != NULL){
2619
2620
struct dirent **direntries = NULL;
2620
struct dirent *direntry = NULL;
2621
int numentries = scandir(tempdir, &direntries, notdotentries,
2624
for(int i = 0; i < numentries; i++){
2625
direntry = direntries[i];
2626
char *fullname = NULL;
2627
ret = asprintf(&fullname, "%s/%s", tempdir,
2630
perror_plus("asprintf");
2633
ret = remove(fullname);
2635
fprintf_plus(stderr, "remove(\"%s\"): %s\n", fullname,
2621
int tempdir_fd = (int)TEMP_FAILURE_RETRY(open(tempdir, O_RDONLY));
2622
if(tempdir_fd == -1){
2623
perror_plus("open");
2625
int numentries = scandir(tempdir, &direntries, notdotentries,
2628
for(int i = 0; i < numentries; i++){
2629
ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
2631
fprintf_plus(stderr, "unlinkat(open(\"%s\", O_RDONLY),"
2632
" \"%s\", 0): %s\n", tempdir,
2633
direntries[i]->d_name, strerror(errno));
2637
/* need to clean even if 0 because man page doesn't specify */
2639
if(numentries == -1){
2640
perror_plus("scandir");
2642
ret = rmdir(tempdir);
2643
if(ret == -1 and errno != ENOENT){
2644
perror_plus("rmdir");
2642
/* need to clean even if 0 because man page doesn't specify */
2644
if(numentries == -1){
2645
perror_plus("scandir");
2647
ret = rmdir(tempdir);
2648
if(ret == -1 and errno != ENOENT){
2649
perror_plus("rmdir");
2647
TEMP_FAILURE_RETRY(close(tempdir_fd));