bind.2, clone.2, dup.2, futex.2, mprotect.2, open_by_handle_at.2, pivot_root.2, select_tut.2, shmop.2, timer_create.2, userfaultfd.2, getaddrinfo.3, getaddrinfo_a.3, inet_net_pton.3, malloc_info.3, mbstowcs.3, newlocale.3, posix_spawn.3, pthread_sigmask.3, shm_open.3, strtol.3, inotify.7, user_namespaces.7: Add periods at end of sentences in comments

Try to bring a little more consistency on the use of periods
in comments in example code.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2020-12-27 10:56:48 +01:00
parent f18f9c4095
commit c6beb8a167
25 changed files with 153 additions and 153 deletions

View File

@ -307,7 +307,7 @@ main(int argc, char *argv[])
handle_error("listen");
/* Now we can accept incoming connections one
at a time using accept(2) */
at a time using accept(2). */
peer_addr_size = sizeof(peer_addr);
cfd = accept(sfd, (struct sockaddr *) &peer_addr,
@ -318,7 +318,7 @@ main(int argc, char *argv[])
/* Code to deal with incoming connection(s)... */
/* When no longer required, the socket pathname, MY_SOCK_PATH
should be deleted using unlink(2) or remove(3) */
should be deleted using unlink(2) or remove(3). */
}
.EE
.SH SEE ALSO

View File

@ -1830,12 +1830,12 @@ childFunc(void *arg)
{
struct utsname uts;
/* Change hostname in UTS namespace of child */
/* Change hostname in UTS namespace of child. */
if (sethostname(arg, strlen(arg)) == \-1)
errExit("sethostname");
/* Retrieve and display hostname */
/* Retrieve and display hostname. */
if (uname(&uts) == \-1)
errExit("uname");
@ -1865,7 +1865,7 @@ main(int argc, char *argv[])
exit(EXIT_SUCCESS);
}
/* Allocate memory to be used for the stack of the child */
/* Allocate memory to be used for the stack of the child. */
stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, \-1, 0);
@ -1875,7 +1875,7 @@ main(int argc, char *argv[])
stackTop = stack + STACK_SIZE; /* Assume stack grows downward */
/* Create child that has its own UTS namespace;
child commences execution in childFunc() */
child commences execution in childFunc(). */
pid = clone(childFunc, stackTop, CLONE_NEWUTS | SIGCHLD, argv[1]);
if (pid == \-1)

View File

@ -255,21 +255,21 @@ Instead, code something like the following could be used:
tmpfd = dup(newfd);
if (tmpfd == \-1 && errno != EBADF) {
/* Handle unexpected dup() error */
/* Handle unexpected dup() error. */
}
/* Atomically duplicate \(aqoldfd\(aq on \(aqnewfd\(aq */
/* Atomically duplicate \(aqoldfd\(aq on \(aqnewfd\(aq. */
if (dup2(oldfd, newfd) == \-1) {
/* Handle dup2() error */
/* Handle dup2() error. */
}
/* Now check for close() errors on the file originally
referred to by \(aqnewfd\(aq */
referred to by \(aqnewfd\(aq. */
if (tmpfd != \-1) {
if (close(tmpfd) == \-1) {
/* Handle errors from close */
/* Handle errors from close. */
}
}
.EE

View File

@ -1799,7 +1799,7 @@ fwait(uint32_t *futexp)
if (atomic_compare_exchange_strong(futexp, &one, 0))
break; /* Yes */
/* Futex is not available; wait */
/* Futex is not available; wait. */
s = futex(futexp, FUTEX_WAIT, 0, NULL, NULL, 0);
if (s == \-1 && errno != EAGAIN)
@ -1817,7 +1817,7 @@ fpost(uint32_t *futexp)
long s;
/* atomic_compare_exchange_strong() was described
in comments above */
in comments above. */
const uint32_t zero = 0;
if (atomic_compare_exchange_strong(futexp, &zero, 1)) {
@ -1840,7 +1840,7 @@ main(int argc, char *argv[])
/* Create a shared anonymous mapping that will hold the futexes.
Since the futexes are being shared between processes, we
subsequently use the "shared" futex operations (i.e., not the
ones suffixed "_PRIVATE") */
ones suffixed "_PRIVATE"). */
iaddr = mmap(NULL, sizeof(*iaddr) * 2, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_SHARED, \-1, 0);
@ -1854,7 +1854,7 @@ main(int argc, char *argv[])
*futex2 = 1; /* State: available */
/* Create a child process that inherits the shared anonymous
mapping */
mapping. */
childPid = fork();
if (childPid == \-1)
@ -1870,7 +1870,7 @@ main(int argc, char *argv[])
exit(EXIT_SUCCESS);
}
/* Parent falls through to here */
/* Parent falls through to here. */
for (int j = 0; j < nloops; j++) {
fwait(futex2);

View File

@ -347,7 +347,7 @@ main(int argc, char *argv[])
handle_error("sysconf");
/* Allocate a buffer aligned on a page boundary;
initial protection is PROT_READ | PROT_WRITE */
initial protection is PROT_READ | PROT_WRITE. */
buffer = memalign(pagesize, 4 * pagesize);
if (buffer == NULL)

View File

@ -565,7 +565,7 @@ main(int argc, char *argv[])
pathname = argv[1];
/* Allocate file_handle structure */
/* Allocate file_handle structure. */
fhsize = sizeof(*fhp);
fhp = malloc(fhsize);
@ -573,7 +573,7 @@ main(int argc, char *argv[])
errExit("malloc");
/* Make an initial call to name_to_handle_at() to discover
the size required for file handle */
the size required for file handle. */
dirfd = AT_FDCWD; /* For name_to_handle_at() calls */
flags = 0; /* For name_to_handle_at() calls */
@ -584,20 +584,20 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* Reallocate file_handle structure with correct size */
/* Reallocate file_handle structure with correct size. */
fhsize = sizeof(*fhp) + fhp\->handle_bytes;
fhp = realloc(fhp, fhsize); /* Copies fhp\->handle_bytes */
if (fhp == NULL)
errExit("realloc");
/* Get file handle from pathname supplied on command line */
/* Get file handle from pathname supplied on command line. */
if (name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags) == \-1)
errExit("name_to_handle_at");
/* Write mount ID, file handle size, and file handle to stdout,
for later reuse by t_open_by_handle_at.c */
for later reuse by t_open_by_handle_at.c. */
printf("%d\en", mount_id);
printf("%u %d ", fhp\->handle_bytes, fhp\->handle_type);
@ -705,7 +705,7 @@ main(int argc, char *argv[])
handle_bytes = strtoul(line2, &nextp, 0);
/* Given handle_bytes, we can now allocate file_handle structure */
/* Given handle_bytes, we can now allocate file_handle structure. */
fhp = malloc(sizeof(*fhp) + handle_bytes);
if (fhp == NULL)
@ -731,13 +731,13 @@ main(int argc, char *argv[])
if (mount_fd == \-1)
errExit("opening mount fd");
/* Open file using handle and mount point */
/* Open file using handle and mount point. */
fd = open_by_handle_at(mount_fd, fhp, O_RDONLY);
if (fd == \-1)
errExit("open_by_handle_at");
/* Try reading a few bytes from the file */
/* Try reading a few bytes from the file. */
nread = read(fd, buf, sizeof(buf));
if (nread == \-1)

View File

@ -347,33 +347,33 @@ child(void *arg)
/* Ensure that \(aqnew_root\(aq and its parent mount don\(aqt have
shared propagation (which would cause pivot_root() to
return an error), and prevent propagation of mount
events to the initial mount namespace */
events to the initial mount namespace. */
if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL) == \-1)
errExit("mount\-MS_PRIVATE");
/* Ensure that \(aqnew_root\(aq is a mount point */
/* Ensure that \(aqnew_root\(aq is a mount point. */
if (mount(new_root, new_root, NULL, MS_BIND, NULL) == \-1)
errExit("mount\-MS_BIND");
/* Create directory to which old root will be pivoted */
/* Create directory to which old root will be pivoted. */
snprintf(path, sizeof(path), "%s/%s", new_root, put_old);
if (mkdir(path, 0777) == \-1)
errExit("mkdir");
/* And pivot the root filesystem */
/* And pivot the root filesystem. */
if (pivot_root(new_root, path) == \-1)
errExit("pivot_root");
/* Switch the current working directory to "/" */
/* Switch the current working directory to "/". */
if (chdir("/") == \-1)
errExit("chdir");
/* Unmount old root and remove mount point */
/* Unmount old root and remove mount point. */
if (umount2(put_old, MNT_DETACH) == \-1)
perror("umount2");
@ -389,7 +389,7 @@ child(void *arg)
int
main(int argc, char *argv[])
{
/* Create a child process in a new mount namespace */
/* Create a child process in a new mount namespace. */
char *stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, \-1, 0);
@ -400,7 +400,7 @@ main(int argc, char *argv[])
CLONE_NEWNS | SIGCHLD, &argv[1]) == \-1)
errExit("clone");
/* Parent falls through to here; wait for child */
/* Parent falls through to here; wait for child. */
if (wait(NULL) == \-1)
errExit("wait");

View File

@ -546,7 +546,7 @@ main(int argc, char *argv[])
}
}
/* NB: read OOB data before normal reads */
/* NB: read OOB data before normal reads. */
if (fd1 > 0 && FD_ISSET(fd1, &exceptfds)) {
char c;
@ -599,7 +599,7 @@ main(int argc, char *argv[])
buf1_written += nbytes;
}
/* Check if write data has caught read data */
/* Check if write data has caught read data. */
if (buf1_written == buf1_avail)
buf1_written = buf1_avail = 0;
@ -607,7 +607,7 @@ main(int argc, char *argv[])
buf2_written = buf2_avail = 0;
/* One side has closed the connection, keep
writing to the other side until empty */
writing to the other side until empty. */
if (fd1 < 0 && buf1_avail \- buf1_written == 0)
SHUT_FD2;

View File

@ -386,7 +386,7 @@ main(int argc, char *argv[])
char *addr;
/* Create shared memory and semaphore set containing one
semaphore */
semaphore. */
shmid = shmget(IPC_PRIVATE, MEM_SIZE, IPC_CREAT | 0600);
if (shmid == \-1)
@ -396,13 +396,13 @@ main(int argc, char *argv[])
if (shmid == \-1)
errExit("shmget");
/* Attach shared memory into our address space */
/* Attach shared memory into our address space. */
addr = shmat(shmid, NULL, SHM_RDONLY);
if (addr == (void *) \-1)
errExit("shmat");
/* Initialize semaphore 0 in set with value 1 */
/* Initialize semaphore 0 in set with value 1. */
arg.val = 1;
if (semctl(semid, 0, SETVAL, arg) == \-1)
@ -410,7 +410,7 @@ main(int argc, char *argv[])
printf("shmid = %d; semid = %d\en", shmid, semid);
/* Wait for semaphore value to become 0 */
/* Wait for semaphore value to become 0. */
sop.sem_num = 0;
sop.sem_op = 0;
@ -419,11 +419,11 @@ main(int argc, char *argv[])
if (semop(semid, &sop, 1) == \-1)
errExit("semop");
/* Print the string from shared memory */
/* Print the string from shared memory. */
printf("%s\en", addr);
/* Remove shared memory and semaphore set */
/* Remove shared memory and semaphore set. */
if (shmctl(shmid, IPC_RMID, NULL) == \-1)
errExit("shmctl");
@ -470,7 +470,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* Get object IDs from command\-line */
/* Get object IDs from command\-line. */
shmid = atoi(argv[1]);
semid = atoi(argv[2]);
@ -484,7 +484,7 @@ main(int argc, char *argv[])
memcpy(addr, argv[3], len);
/* Decrement semaphore to 0 */
/* Decrement semaphore to 0. */
sop.sem_num = 0;
sop.sem_op = \-1;

View File

@ -430,7 +430,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* Establish handler for timer signal */
/* Establish handler for timer signal. */
printf("Establishing handler for signal %d\en", SIG);
sa.sa_flags = SA_SIGINFO;
@ -439,7 +439,7 @@ main(int argc, char *argv[])
if (sigaction(SIG, &sa, NULL) == \-1)
errExit("sigaction");
/* Block timer signal temporarily */
/* Block timer signal temporarily. */
printf("Blocking signal %d\en", SIG);
sigemptyset(&mask);
@ -447,7 +447,7 @@ main(int argc, char *argv[])
if (sigprocmask(SIG_SETMASK, &mask, NULL) == \-1)
errExit("sigprocmask");
/* Create the timer */
/* Create the timer. */
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIG;
@ -457,7 +457,7 @@ main(int argc, char *argv[])
printf("timer ID is %#jx\en", (uintmax_t) timerid);
/* Start the timer */
/* Start the timer. */
freq_nanosecs = atoll(argv[2]);
its.it_value.tv_sec = freq_nanosecs / 1000000000;
@ -469,13 +469,13 @@ main(int argc, char *argv[])
errExit("timer_settime");
/* Sleep for a while; meanwhile, the timer may expire
multiple times */
multiple times. */
printf("Sleeping for %d seconds\en", atoi(argv[1]));
sleep(atoi(argv[1]));
/* Unlock the timer signal, so that timer notification
can be delivered */
can be delivered. */
printf("Unblocking signal %d\en", SIG);
if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == \-1)

View File

@ -600,7 +600,7 @@ fault_handler_thread(void *arg)
uffd = (long) arg;
/* Create a page that will be copied into the faulting region */
/* Create a page that will be copied into the faulting region. */
if (page == NULL) {
page = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
@ -610,11 +610,11 @@ fault_handler_thread(void *arg)
}
/* Loop, handling incoming events on the userfaultfd
file descriptor */
file descriptor. */
for (;;) {
/* See what poll() tells us about the userfaultfd */
/* See what poll() tells us about the userfaultfd. */
struct pollfd pollfd;
int nready;
@ -630,7 +630,7 @@ fault_handler_thread(void *arg)
(pollfd.revents & POLLIN) != 0,
(pollfd.revents & POLLERR) != 0);
/* Read an event from the userfaultfd */
/* Read an event from the userfaultfd. */
nread = read(uffd, &msg, sizeof(msg));
if (nread == 0) {
@ -641,14 +641,14 @@ fault_handler_thread(void *arg)
if (nread == \-1)
errExit("read");
/* We expect only one kind of event; verify that assumption */
/* We expect only one kind of event; verify that assumption. */
if (msg.event != UFFD_EVENT_PAGEFAULT) {
fprintf(stderr, "Unexpected event on userfaultfd\en");
exit(EXIT_FAILURE);
}
/* Display info about the page\-fault event */
/* Display info about the page\-fault event. */
printf(" UFFD_EVENT_PAGEFAULT event: ");
printf("flags = %"PRIx64"; ", msg.arg.pagefault.flags);
@ -664,7 +664,7 @@ fault_handler_thread(void *arg)
uffdio_copy.src = (unsigned long) page;
/* We need to handle page faults in units of pages(!).
So, round faulting address down to page boundary */
So, round faulting address down to page boundary. */
uffdio_copy.dst = (unsigned long) msg.arg.pagefault.address &
\(ti(page_size \- 1);
@ -698,7 +698,7 @@ main(int argc, char *argv[])
page_size = sysconf(_SC_PAGE_SIZE);
len = strtoull(argv[1], NULL, 0) * page_size;
/* Create and enable userfaultfd object */
/* Create and enable userfaultfd object. */
uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
if (uffd == \-1)
@ -731,7 +731,7 @@ main(int argc, char *argv[])
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == \-1)
errExit("ioctl\-UFFDIO_REGISTER");
/* Create a thread that will process the userfaultfd events */
/* Create a thread that will process the userfaultfd events. */
s = pthread_create(&thr, NULL, fault_handler_thread, (void *) uffd);
if (s != 0) {
@ -746,7 +746,7 @@ main(int argc, char *argv[])
int l;
l = 0xf; /* Ensure that faulting address is not on a page
boundary, in order to test that we correctly
handle that case in fault_handling_thread() */
handle that case in fault_handling_thread(). */
while (l < len) {
char c = addr[l];
printf("Read address %p in main(): ", addr + l);

View File

@ -718,7 +718,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* Read datagrams and echo them back to sender */
/* Read datagrams and echo them back to sender. */
for (;;) {
peer_addr_len = sizeof(peer_addr);
@ -773,7 +773,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* Obtain address(es) matching host/port */
/* Obtain address(es) matching host/port. */
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
@ -812,7 +812,7 @@ main(int argc, char *argv[])
}
/* Send remaining command\-line arguments as separate
datagrams, and read responses from server */
datagrams, and read responses from server. */
for (int j = 3; j < argc; j++) {
len = strlen(argv[j]) + 1;

View File

@ -463,7 +463,7 @@ getcmd(void)
return buf;
}
/* Add requests for specified hostnames */
/* Add requests for specified hostnames. */
static void
add_requests(void)
{
@ -490,7 +490,7 @@ add_requests(void)
}
}
/* Wait until at least one of specified requests completes */
/* Wait until at least one of specified requests completes. */
static void
wait_requests(void)
{
@ -529,7 +529,7 @@ wait_requests(void)
}
}
/* Cancel specified requests */
/* Cancel specified requests. */
static void
cancel_requests(void)
{
@ -550,7 +550,7 @@ cancel_requests(void)
}
}
/* List all requests */
/* List all requests. */
static void
list_requests(void)
{

View File

@ -360,7 +360,7 @@ main(int argc, char *argv[])
addr.s_addr = (argc > 2) ? strtod(argv[2], NULL) : 0;
/* Convert presentation network number in argv[1] to binary */
/* Convert presentation network number in argv[1] to binary. */
bits = inet_net_pton(AF_INET, argv[1], &addr, sizeof(addr));
if (bits == \-1)
@ -369,7 +369,7 @@ main(int argc, char *argv[])
printf("inet_net_pton() returned: %d\en", bits);
/* Convert binary format back to presentation, using \(aqbits\(aq
returned by inet_net_pton() */
returned by inet_net_pton(). */
if (inet_net_ntop(AF_INET, &addr, bits, buf, sizeof(buf)) == NULL)
errExit("inet_net_ntop");

View File

@ -197,13 +197,13 @@ thread_func(void *arg)
int tn = (int) arg;
/* The multiplier \(aq(2 + tn)\(aq ensures that each thread (including
the main thread) allocates a different amount of memory */
the main thread) allocates a different amount of memory. */
for (int j = 0; j < numBlocks; j++)
if (malloc(blockSize * (2 + tn)) == NULL)
errExit("malloc\-thread");
sleep(100); /* Sleep until main thread terminates */
sleep(100); /* Sleep until main thread terminates. */
return NULL;
}
@ -231,7 +231,7 @@ main(int argc, char *argv[])
printf("============ Before allocating blocks ============\en");
malloc_info(0, stdout);
/* Create threads that allocate different amounts of memory */
/* Create threads that allocate different amounts of memory. */
for (int tn = 0; tn < numThreads; tn++) {
errno = pthread_create(&thr[tn], NULL, thread_func,
@ -248,14 +248,14 @@ main(int argc, char *argv[])
sleep(sleepTime);
}
/* The main thread also allocates some memory */
/* The main thread also allocates some memory. */
for (int j = 0; j < numBlocks; j++)
if (malloc(blockSize) == NULL)
errExit("malloc");
sleep(2); /* Give all threads a chance to
complete allocations */
complete allocations. */
printf("\en============ After allocating blocks ============\en");
malloc_info(0, stdout);

View File

@ -160,7 +160,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* Apply the specified locale */
/* Apply the specified locale. */
if (setlocale(LC_ALL, argv[1]) == NULL) {
perror("setlocale");
@ -168,7 +168,7 @@ main(int argc, char *argv[])
}
/* Calculate the length required to hold argv[2] converted to
a wide character string */
a wide character string. */
mbslen = mbstowcs(NULL, argv[2], 0);
if (mbslen == (size_t) \-1) {
@ -176,7 +176,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* Describe the source string to the user */
/* Describe the source string to the user. */
printf("Length of source string (excluding terminator):\en");
printf(" %zu bytes\en", strlen(argv[2]));
@ -192,7 +192,7 @@ main(int argc, char *argv[])
}
/* Convert the multibyte character string in argv[2] to a
wide character string */
wide character string. */
if (mbstowcs(wcs, argv[2], mbslen + 1) == (size_t) \-1) {
perror("mbstowcs");
@ -203,7 +203,7 @@ main(int argc, char *argv[])
wcs, mbslen);
/* Now do some inspection of the classes of the characters in
the wide character string */
the wide character string. */
for (wchar_t *wp = wcs; *wp != 0; wp++) {
printf(" %lc ", (wint_t) *wp);

View File

@ -323,7 +323,7 @@ main(int argc, char *argv[])
}
/* Create a new locale object, taking the LC_NUMERIC settings
from the locale specified in argv[1] */
from the locale specified in argv[1]. */
loc = newlocale(LC_NUMERIC_MASK, argv[1], (locale_t) 0);
if (loc == (locale_t) 0)
@ -342,15 +342,15 @@ main(int argc, char *argv[])
loc = nloc;
}
/* Apply the newly created locale to this thread */
/* Apply the newly created locale to this thread. */
uselocale(loc);
/* Test effect of LC_NUMERIC */
/* Test effect of LC_NUMERIC. */
printf("%8.3f\en", 123456.789);
/* Test effect of LC_TIME */
/* Test effect of LC_TIME. */
t = time(NULL);
tm = localtime(&t);
@ -363,7 +363,7 @@ main(int argc, char *argv[])
printf("%s\en", buf);
/* Free the locale object */
/* Free the locale object. */
uselocale(LC_GLOBAL_HANDLE); /* So \(aqloc\(aq is no longer in use */
freelocale(loc);

View File

@ -721,7 +721,7 @@ main(int argc, char *argv[])
case \(aqc\(aq: /* \-c: close standard output in child */
/* Create a file actions object and add a "close"
action to it */
action to it. */
s = posix_spawn_file_actions_init(&file_actions);
if (s != 0)
@ -738,7 +738,7 @@ main(int argc, char *argv[])
case \(aqs\(aq: /* \-s: block all signals in child */
/* Create an attributes object and add a "set signal mask"
action to it */
action to it. */
s = posix_spawnattr_init(&attr);
if (s != 0)
@ -767,7 +767,7 @@ main(int argc, char *argv[])
if (s != 0)
errExitEN(s, "posix_spawn");
/* Destroy any objects that we created earlier */
/* Destroy any objects that we created earlier. */
if (attrp != NULL) {
s = posix_spawnattr_destroy(attrp);
@ -783,7 +783,7 @@ main(int argc, char *argv[])
printf("PID of child: %jd\en", (intmax_t) child_pid);
/* Monitor status of the child until it terminates */
/* Monitor status of the child until it terminates. */
do {
s = waitpid(child_pid, &status, WUNTRACED | WCONTINUED);

View File

@ -325,7 +325,7 @@ main(int argc, char *argv[])
char *attr_sched_str, *main_sched_str, *inheritsched_str;
struct sched_param param;
/* Process command\-line options */
/* Process command\-line options. */
use_null_attrib = 0;
attr_sched_str = NULL;
@ -347,7 +347,7 @@ main(int argc, char *argv[])
usage(argv[0], "Can\(aqt specify \-A with \-i or \-a\en");
/* Optionally set scheduling attributes of main thread,
and display the attributes */
and display the attributes. */
if (main_sched_str != NULL) {
if (!get_policy(main_sched_str[0], &policy))
@ -362,7 +362,7 @@ main(int argc, char *argv[])
display_thread_sched_attr("Scheduler settings of main thread");
printf("\en");
/* Initialize thread attributes object according to options */
/* Initialize thread attributes object according to options. */
attrp = NULL;
@ -401,7 +401,7 @@ main(int argc, char *argv[])
}
/* If we initialized a thread attributes object, display
the scheduling attributes that were set in the object */
the scheduling attributes that were set in the object. */
if (attrp != NULL) {
s = pthread_attr_getschedparam(&attr, &param);
@ -422,13 +422,13 @@ main(int argc, char *argv[])
printf("\en");
}
/* Create a thread that will display its scheduling attributes */
/* Create a thread that will display its scheduling attributes. */
s = pthread_create(&thread, attrp, &thread_start, NULL);
if (s != 0)
handle_error_en(s, "pthread_create");
/* Destroy unneeded thread attributes object */
/* Destroy unneeded thread attributes object. */
if (!use_null_attrib) {
s = pthread_attr_destroy(&attr);

View File

@ -159,7 +159,7 @@ main(int argc, char *argv[])
handle_error_en(s, "pthread_create");
/* Main thread carries on to create other threads and/or do
other work */
other work. */
pause(); /* Dummy pause so we can test program */
}

View File

@ -370,7 +370,7 @@ main(int argc, char *argv[])
char *shmpath = argv[1];
/* Create shared memory object and set its size to the size
of our structure */
of our structure. */
int fd = shm_open(shmpath, O_CREAT | O_EXCL | O_RDWR,
S_IRUSR | S_IWUSR);
@ -380,7 +380,7 @@ main(int argc, char *argv[])
if (ftruncate(fd, sizeof(struct shmbuf)) == \-1)
errExit("ftruncate");
/* Map the object into the caller\(aqs address space */
/* Map the object into the caller\(aqs address space. */
struct shmbuf *shmp = mmap(NULL, sizeof(*shmp),
PROT_READ | PROT_WRITE,
@ -388,7 +388,7 @@ main(int argc, char *argv[])
if (shmp == MAP_FAILED)
errExit("mmap");
/* Initialize semaphores as process-shared, with value 0 */
/* Initialize semaphores as process-shared, with value 0. */
if (sem_init(&shmp\->sem1, 1, 0) == \-1)
errExit("sem_init\-sem1");
@ -396,18 +396,18 @@ main(int argc, char *argv[])
errExit("sem_init\-sem2");
/* Wait for \(aqsem1\(aq to be posted by peer before touching
shared memory */
shared memory. */
if (sem_wait(&shmp\->sem1) == \-1)
errExit("sem_wait");
/* Convert data in shared memory into upper case */
/* Convert data in shared memory into upper case. */
for (int j = 0; j < shmp\->cnt; j++)
shmp\->buf[j] = toupper((unsigned char) shmp\->buf[j]);
/* Post \(aqsem2\(aq to tell the to tell peer that it can now
access the modified data in shared memory */
access the modified data in shared memory. */
if (sem_post(&shmp\->sem2) == \-1)
errExit("sem_post");
@ -465,7 +465,7 @@ main(int argc, char *argv[])
}
/* Open the existing shared memory object and map it
into the caller\(aqs address space */
into the caller\(aqs address space. */
int fd = shm_open(shmpath, O_RDWR, 0);
if (fd == \-1)
@ -477,23 +477,23 @@ main(int argc, char *argv[])
if (shmp == MAP_FAILED)
errExit("mmap");
/* Copy data into the shared memory object */
/* Copy data into the shared memory object. */
shmp\->cnt = len;
memcpy(&shmp\->buf, string, len);
/* Tell peer that it can now access shared memory */
/* Tell peer that it can now access shared memory. */
if (sem_post(&shmp\->sem1) == \-1)
errExit("sem_post");
/* Wait until peer says that it has finished accessing
the shared memory */
the shared memory. */
if (sem_wait(&shmp\->sem2) == \-1)
errExit("sem_wait");
/* Write modified data in shared memory to standard output */
/* Write modified data in shared memory to standard output. */
write(STDOUT_FILENO, &shmp\->buf, len);
write(STDOUT_FILENO, "\en", 1);

View File

@ -274,7 +274,7 @@ main(int argc, char *argv[])
errno = 0; /* To distinguish success/failure after call */
val = strtol(str, &endptr, base);
/* Check for various possible errors */
/* Check for various possible errors. */
if (errno != 0) {
perror("strtol");
@ -286,7 +286,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* If we got here, strtol() successfully parsed a number */
/* If we got here, strtol() successfully parsed a number. */
printf("strtol() returned %ld\en", val);

View File

@ -800,7 +800,7 @@ Listening for events stopped.
#include <sys/fanotify.h>
#include <unistd.h>
/* Read all available fanotify events from the file descriptor \(aqfd\(aq */
/* Read all available fanotify events from the file descriptor \(aqfd\(aq. */
static void
handle_events(int fd)
@ -813,11 +813,11 @@ handle_events(int fd)
char procfd_path[PATH_MAX];
struct fanotify_response response;
/* Loop while events can be read from fanotify file descriptor */
/* Loop while events can be read from fanotify file descriptor. */
for (;;) {
/* Read some events */
/* Read some events. */
len = read(fd, buf, sizeof(buf));
if (len == \-1 && errno != EAGAIN) {
@ -825,20 +825,20 @@ handle_events(int fd)
exit(EXIT_FAILURE);
}
/* Check if end of available data reached */
/* Check if end of available data reached. */
if (len <= 0)
break;
/* Point to the first event in the buffer */
/* Point to the first event in the buffer. */
metadata = buf;
/* Loop over all events in the buffer */
/* Loop over all events in the buffer. */
while (FAN_EVENT_OK(metadata, len)) {
/* Check that run\-time and compile\-time structures match */
/* Check that run\-time and compile\-time structures match. */
if (metadata\->vers != FANOTIFY_METADATA_VERSION) {
fprintf(stderr,
@ -852,24 +852,24 @@ handle_events(int fd)
if (metadata\->fd >= 0) {
/* Handle open permission event */
/* Handle open permission event. */
if (metadata\->mask & FAN_OPEN_PERM) {
printf("FAN_OPEN_PERM: ");
/* Allow file to be opened */
/* Allow file to be opened. */
response.fd = metadata\->fd;
response.response = FAN_ALLOW;
write(fd, &response, sizeof(response));
}
/* Handle closing of writable file event */
/* Handle closing of writable file event. */
if (metadata\->mask & FAN_CLOSE_WRITE)
printf("FAN_CLOSE_WRITE: ");
/* Retrieve and print pathname of the accessed file */
/* Retrieve and print pathname of the accessed file. */
snprintf(procfd_path, sizeof(procfd_path),
"/proc/self/fd/%d", metadata\->fd);
@ -883,12 +883,12 @@ handle_events(int fd)
path[path_len] = \(aq\e0\(aq;
printf("File %s\en", path);
/* Close the file descriptor of the event */
/* Close the file descriptor of the event. */
close(metadata\->fd);
}
/* Advance to next event */
/* Advance to next event. */
metadata = FAN_EVENT_NEXT(metadata, len);
}
@ -903,7 +903,7 @@ main(int argc, char *argv[])
nfds_t nfds;
struct pollfd fds[2];
/* Check mount point is supplied */
/* Check mount point is supplied. */
if (argc != 2) {
fprintf(stderr, "Usage: %s MOUNT\en", argv[0]);
@ -912,7 +912,7 @@ main(int argc, char *argv[])
printf("Press enter key to terminate.\en");
/* Create the file descriptor for accessing the fanotify API */
/* Create the file descriptor for accessing the fanotify API. */
fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK,
O_RDONLY | O_LARGEFILE);
@ -924,7 +924,7 @@ main(int argc, char *argv[])
/* Mark the mount for:
\- permission events before opening files
\- notification events after closing a write\-enabled
file descriptor */
file descriptor. */
if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,
FAN_OPEN_PERM | FAN_CLOSE_WRITE, AT_FDCWD,
@ -933,7 +933,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
/* Prepare for polling */
/* Prepare for polling. */
nfds = 2;
@ -947,7 +947,7 @@ main(int argc, char *argv[])
fds[1].fd = fd;
fds[1].events = POLLIN;
/* This is the loop to wait for incoming events */
/* This is the loop to wait for incoming events. */
printf("Listening for events.\en");
@ -964,7 +964,7 @@ main(int argc, char *argv[])
if (poll_num > 0) {
if (fds[0].revents & POLLIN) {
/* Console input is available: empty stdin and quit */
/* Console input is available: empty stdin and quit. */
while (read(STDIN_FILENO, &buf, 1) > 0 && buf != \(aq\en\(aq)
continue;
@ -973,7 +973,7 @@ main(int argc, char *argv[])
if (fds[1].revents & POLLIN) {
/* Fanotify events are available */
/* Fanotify events are available. */
handle_events(fd);
}
@ -1111,7 +1111,7 @@ main(int argc, char **argv)
printf("Listening for events.\en");
/* Read events from the event queue into a buffer */
/* Read events from the event queue into a buffer. */
len = read(fd, events_buf, sizeof(events_buf));
if (len == \-1 && errno != EAGAIN) {
@ -1119,7 +1119,7 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
/* Process all events within the buffer */
/* Process all events within the buffer. */
for (metadata = (struct fanotify_event_metadata *) events_buf;
FAN_EVENT_OK(metadata, len);
@ -1127,7 +1127,7 @@ main(int argc, char **argv)
fid = (struct fanotify_event_info_fid *) (metadata + 1);
file_handle = (struct file_handle *) fid\->handle;
/* Ensure that the event info is of the correct type */
/* Ensure that the event info is of the correct type. */
if (fid\->hdr.info_type == FAN_EVENT_INFO_TYPE_FID ||
fid\->hdr.info_type == FAN_EVENT_INFO_TYPE_DFID) {
@ -1170,7 +1170,7 @@ main(int argc, char **argv)
snprintf(procfd_path, sizeof(procfd_path), "/proc/self/fd/%d",
event_fd);
/* Retrieve and print the path of the modified dentry */
/* Retrieve and print the path of the modified dentry. */
path_len = readlink(procfd_path, path, sizeof(path) \- 1);
if (path_len == \-1) {
@ -1197,7 +1197,7 @@ main(int argc, char **argv)
}
}
/* Close associated file descriptor for this event */
/* Close associated file descriptor for this event. */
close(event_fd);
}

View File

@ -963,14 +963,14 @@ handle_events(int fd, int *wd, int argc, char* argv[])
if (len <= 0)
break;
/* Loop over all events in the buffer */
/* Loop over all events in the buffer. */
for (char *ptr = buf; ptr < buf + len;
ptr += sizeof(struct inotify_event) + event\->len) {
event = (const struct inotify_event *) ptr;
/* Print event type */
/* Print event type. */
if (event\->mask & IN_OPEN)
printf("IN_OPEN: ");
@ -979,7 +979,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])
if (event\->mask & IN_CLOSE_WRITE)
printf("IN_CLOSE_WRITE: ");
/* Print the name of the watched directory */
/* Print the name of the watched directory. */
for (int i = 1; i < argc; ++i) {
if (wd[i] == event\->wd) {
@ -988,12 +988,12 @@ handle_events(int fd, int *wd, int argc, char* argv[])
}
}
/* Print the name of the file */
/* Print the name of the file. */
if (event\->len)
printf("%s", event\->name);
/* Print type of filesystem object */
/* Print type of filesystem object. */
if (event\->mask & IN_ISDIR)
printf(" [directory]\en");
@ -1019,7 +1019,7 @@ main(int argc, char* argv[])
printf("Press ENTER key to terminate.\en");
/* Create the file descriptor for accessing the inotify API */
/* Create the file descriptor for accessing the inotify API. */
fd = inotify_init1(IN_NONBLOCK);
if (fd == \-1) {
@ -1027,7 +1027,7 @@ main(int argc, char* argv[])
exit(EXIT_FAILURE);
}
/* Allocate memory for watch descriptors */
/* Allocate memory for watch descriptors. */
wd = calloc(argc, sizeof(int));
if (wd == NULL) {
@ -1049,7 +1049,7 @@ main(int argc, char* argv[])
}
}
/* Prepare for polling */
/* Prepare for polling. */
nfds = 2;
@ -1063,7 +1063,7 @@ main(int argc, char* argv[])
fds[1].fd = fd;
fds[1].events = POLLIN;
/* Wait for events and/or terminal input */
/* Wait for events and/or terminal input. */
printf("Listening for events.\en");
while (1) {
@ -1079,7 +1079,7 @@ main(int argc, char* argv[])
if (fds[0].revents & POLLIN) {
/* Console input is available. Empty stdin and quit */
/* Console input is available. Empty stdin and quit. */
while (read(STDIN_FILENO, &buf, 1) > 0 && buf != \(aq\en\(aq)
continue;
@ -1088,7 +1088,7 @@ main(int argc, char* argv[])
if (fds[1].revents & POLLIN) {
/* Inotify events are available */
/* Inotify events are available. */
handle_events(fd, wd, argc, argv);
}
@ -1097,7 +1097,7 @@ main(int argc, char* argv[])
printf("Listening for events stopped.\en");
/* Close inotify file descriptor */
/* Close inotify file descriptor. */
close(fd);

View File

@ -1087,7 +1087,7 @@ CapEff: 0000001fffffffff
#include <errno.h>
/* A simple error\-handling function: print an error message based
on the value in \(aqerrno\(aq and terminate the calling process */
on the value in \(aqerrno\(aq and terminate the calling process. */
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
@ -1153,7 +1153,7 @@ update_map(char *mapping, char *map_file)
int fd;
size_t map_len; /* Length of \(aqmapping\(aq */
/* Replace commas in mapping string with newlines */
/* Replace commas in mapping string with newlines. */
map_len = strlen(mapping);
for (int j = 0; j < map_len; j++)
@ -1233,7 +1233,7 @@ childFunc(void *arg)
close(args\->pipe_fd[1]); /* Close our descriptor for the write
end of the pipe so that we see EOF
when parent closes its descriptor */
when parent closes its descriptor. */
if (read(args\->pipe_fd[0], &ch, 1) != 0) {
fprintf(stderr,
"Failure in child: read from pipe returned != 0\en");
@ -1242,7 +1242,7 @@ childFunc(void *arg)
close(args\->pipe_fd[0]);
/* Execute a shell command */
/* Execute a shell command. */
printf("About to exec %s\en", args\->argv[0]);
execvp(args\->argv[0], args\->argv);
@ -1314,20 +1314,20 @@ main(int argc, char *argv[])
if (pipe(args.pipe_fd) == \-1)
errExit("pipe");
/* Create the child in new namespace(s) */
/* Create the child in new namespace(s). */
child_pid = clone(childFunc, child_stack + STACK_SIZE,
flags | SIGCHLD, &args);
if (child_pid == \-1)
errExit("clone");
/* Parent falls through to here */
/* Parent falls through to here. */
if (verbose)
printf("%s: PID of child created by clone() is %jd\en",
argv[0], (intmax_t) child_pid);
/* Update the UID and GID maps in the child */
/* Update the UID and GID maps in the child. */
if (uid_map != NULL || map_zero) {
snprintf(map_path, PATH_MAX, "/proc/%jd/uid_map",
@ -1354,7 +1354,7 @@ main(int argc, char *argv[])
}
/* Close the write end of the pipe, to signal to the child that we
have updated the UID and GID maps */
have updated the UID and GID maps. */
close(args.pipe_fd[1]);