Skip to content

Commit 0635476

Browse files
committed
e2ghelper: better names for variables
1 parent a29d317 commit 0635476

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

tools/e2ghelper.cpp

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,38 +56,45 @@ int main(int argc, char **argv) try
5656
perror("pipe");
5757
return EXIT_FAILURE;
5858
}
59-
std::unique_ptr<const char *[]> p1argv(new const char *[argc+2]);
60-
const char *p2argv[4];
61-
int p1argc = 0, p2argc = 0;
62-
p1argv[p1argc++] = "gromox-pff2mt";
59+
60+
/* Arguments for subprograms */
61+
std::unique_ptr<const char *[]> pff_argv(new const char *[argc+2]);
62+
const char *import_argv[4];
63+
int pff_argc = 0, import_argc = 0;
64+
pff_argv[pff_argc++] = "gromox-pff2mt";
6365
if (g_splice)
64-
p1argv[p1argc++] = "-s";
66+
pff_argv[pff_argc++] = "-s";
6567
for (int i = 1; i < argc; ++i)
66-
p1argv[p1argc++] = argv[i];
67-
p1argv[p1argc] = nullptr;
68-
p2argv[p2argc++] = "gromox-mt2exm";
68+
pff_argv[pff_argc++] = argv[i];
69+
pff_argv[pff_argc] = nullptr;
70+
71+
import_argv[import_argc++] = "gromox-mt2exm";
6972
if (g_username != nullptr) {
70-
p2argv[p2argc++] = "-u";
71-
p2argv[p2argc++] = g_username;
73+
import_argv[import_argc++] = "-u";
74+
import_argv[import_argc++] = g_username;
7275
}
73-
p2argv[p2argc] = nullptr;
74-
file_actions p1fa, p2fa;
76+
import_argv[import_argc] = nullptr;
77+
78+
/* File descriptor control block */
79+
file_actions pff_actions, import_actions;
7580
if (pfd[0] != STDIN_FILENO) {
76-
if (posix_spawn_file_actions_adddup2(&p2fa, pfd[0], STDIN_FILENO) != 0 ||
77-
posix_spawn_file_actions_addclose(&p2fa, pfd[0]) != 0 ||
78-
posix_spawn_file_actions_addclose(&p2fa, pfd[1]) != 0) {
81+
if (posix_spawn_file_actions_adddup2(&import_actions, pfd[0], STDIN_FILENO) != 0 ||
82+
posix_spawn_file_actions_addclose(&import_actions, pfd[0]) != 0 ||
83+
posix_spawn_file_actions_addclose(&import_actions, pfd[1]) != 0) {
7984
perror("file_actions");
8085
return EXIT_FAILURE;
8186
}
8287
}
8388
if (pfd[1] != STDOUT_FILENO) {
84-
if (posix_spawn_file_actions_adddup2(&p1fa, pfd[1], STDOUT_FILENO) != 0 ||
85-
posix_spawn_file_actions_addclose(&p1fa, pfd[0]) != 0 ||
86-
posix_spawn_file_actions_addclose(&p1fa, pfd[1]) != 0) {
89+
if (posix_spawn_file_actions_adddup2(&pff_actions, pfd[1], STDOUT_FILENO) != 0 ||
90+
posix_spawn_file_actions_addclose(&pff_actions, pfd[0]) != 0 ||
91+
posix_spawn_file_actions_addclose(&pff_actions, pfd[1]) != 0) {
8792
perror("file_actions");
8893
return EXIT_FAILURE;
8994
}
9095
}
96+
97+
/* Process spin-up */
9198
struct sigaction sact{};
9299
sigemptyset(&sact.sa_mask);
93100
sact.sa_handler = [](int) {};
@@ -96,29 +103,31 @@ int main(int argc, char **argv) try
96103
perror("sigaction");
97104
return EXIT_FAILURE;
98105
}
99-
pid_t p1id = -1, p2id = -1;
100-
auto ret = posix_spawnp(&p1id, p1argv[0], &p1fa, nullptr,
101-
const_cast<char **>(p1argv.get()), environ);
106+
pid_t pff_id = -1, import_pid = -1;
107+
auto ret = posix_spawnp(&pff_id, pff_argv[0], &pff_actions, nullptr,
108+
const_cast<char **>(pff_argv.get()), environ);
102109
if (ret != 0) {
103-
fprintf(stderr, "spawnp %s: %s\n", p1argv[0], strerror(ret));
110+
fprintf(stderr, "spawnp %s: %s\n", pff_argv[0], strerror(ret));
104111
return EXIT_FAILURE;
105112
}
106-
ret = posix_spawnp(&p2id, p2argv[0], &p2fa, nullptr,
107-
const_cast<char **>(p2argv), environ);
113+
ret = posix_spawnp(&import_pid, import_argv[0], &import_actions, nullptr,
114+
const_cast<char **>(import_argv), environ);
108115
if (ret != 0) {
109-
fprintf(stderr, "spawnp %s: %s\n", p2argv[0], strerror(ret));
116+
fprintf(stderr, "spawnp %s: %s\n", import_argv[0], strerror(ret));
110117
return EXIT_FAILURE;
111118
}
112119
close(pfd[0]);
113120
close(pfd[1]);
121+
122+
/* Wait for completion */
114123
int status = 0;
115-
if (waitpid(p1id, &status, 0) < 0) {
124+
if (waitpid(pff_id, &status, 0) < 0) {
116125
perror("waitpid 1");
117126
return EXIT_FAILURE;
118127
}
119128
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
120129
return EXIT_FAILURE;
121-
if (waitpid(p2id, &status, 0) < 0) {
130+
if (waitpid(import_pid, &status, 0) < 0) {
122131
perror("waitpid 2");
123132
return EXIT_FAILURE;
124133
}

0 commit comments

Comments
 (0)