Skip to content

Commit 3240b71

Browse files
committed
mbop: model g_command_num behavior the way it was meant
In a command like mbop -cvu [email protected] \( emptyfld DRAFT \) \( emptyfld -a DRAFT \) there can be many log messages that could indicate failure. (Pathalogic case: exmdb not running.) Prefix them with an indicator to which command they belong. exmdb_client: HX_inet_connect to [::1]:5000: Connection refused /var/lib/gromox/user/horio [cmd 1]: delcount: get_folder_properties failed /var/lib/gromox/user/horio [cmd 1]: empty_folder(DRAFT) failed /var/lib/gromox/user/horio [cmd 1]: delcount: get_folder_properties failed Folder DRAFT: deleted 0 messages, deleted 0 subfolders plus messages /var/lib/gromox/user/horio [cmd 2]: delcount: get_folder_properties failed /var/lib/gromox/user/horio [cmd 2]: empty_folder(DRAFT) failed /var/lib/gromox/user/horio [cmd 2]: delcount: get_folder_properties failed References: GXH-145, GXL-427
1 parent c3cc80e commit 3240b71

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

tools/mbop_foreach.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ int main(int argc, char **argv)
110110
HXOPT_RQ_ORDER | HXOPT_USAGEONERR) != HXOPT_ERR_SUCCESS ||
111111
g_exit_after_optparse)
112112
return EXIT_PARAM;
113-
global::g_command_num = 0;
114113
auto cl_0 = HX::make_scope_exit([=]() { HX_zvecfree(argv); });
115114
if (global::g_arg_username != nullptr || global::g_arg_userdir != nullptr) {
116115
fprintf(stderr, "Cannot use -d/-u with foreach.*\n");
@@ -121,6 +120,7 @@ int main(int argc, char **argv)
121120
auto fe_mode = argv[0];
122121
--argc;
123122
++argv;
123+
++global::g_command_num;
124124
if (argc == 0)
125125
return help();
126126

@@ -182,13 +182,14 @@ int main(int argc, char **argv)
182182
}, &user.maildir, &sem, &ret));
183183
}
184184
} else {
185+
auto saved_cnum = global::g_command_num;
185186
for (auto &&user : ul) {
186187
/* cmd_parser is not thread-safe (global state), cannot parallelize */
187188
g_dstuser = std::move(user.username);
188189
g_storedir_s = std::move(user.maildir);
189190
g_storedir = g_storedir_s.c_str();
191+
global::g_command_num = saved_cnum;
190192
ret = global::cmd_parser(argc, argv);
191-
++global::g_command_num;
192193
if (ret == EXIT_PARAM)
193194
return ret;
194195
else if (ret != EXIT_SUCCESS && !global::g_continuous_mode)

tools/mbop_locale.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int main(int argc, char **argv)
6262
return EXIT_FAILURE;
6363
}
6464
auto orig_name = props.get<const char>(PR_DISPLAY_NAME);
65-
printf("[0x%02x] %s -> %s\n", gcv, znul(orig_name), new_name);
65+
mbop_fprintf(stdout, "[0x%02x] %s -> %s\n", gcv, znul(orig_name), new_name);
6666
}
6767
TAGGED_PROPVAL tp = {PR_DISPLAY_NAME, deconst(new_name)};
6868
const TPROPVAL_ARRAY new_props = {1, &tp};

tools/mbop_main.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void delcount(eid_t fid, uint32_t *delc, uint32_t *fldc)
5454
*delc = *fldc = 0;
5555
if (!exmdb_client->get_folder_properties(g_storedir, CP_ACP, fid,
5656
&taghdr, &props)) {
57-
fprintf(stderr, "delcount: get_folder_properties failed\n");
57+
mbop_fprintf(stderr, "delcount: get_folder_properties failed\n");
5858
return;
5959
}
6060
auto c = props.get<const uint32_t>(tags[0]);
@@ -205,7 +205,7 @@ static int freeze_main(int argc, char **argv)
205205
db_maint_mode::reject_waitforexcl;
206206
auto ok = exmdb_client->set_maintenance(g_storedir, static_cast<uint32_t>(mode));
207207
if (!ok) {
208-
fprintf(stderr, "%s: the operation failed\n", argv[0]);
208+
mbop_fprintf(stderr, "%s: the operation failed\n", argv[0]);
209209
return EXIT_FAILURE;
210210
}
211211
return EXIT_SUCCESS;
@@ -265,11 +265,11 @@ static errno_t showstoreprop(proptag_t proptag)
265265
auto bv = vals.get<const BINARY>(proptag);
266266
if (bv == nullptr) {
267267
if (isatty(STDERR_FILENO))
268-
fprintf(stderr, "Property is unset\n");
268+
mbop_fprintf(stderr, "Property is unset\n");
269269
return 0;
270270
}
271271
if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO))
272-
fprintf(stderr, "[%u bytes of binary data]\n", bv->cb);
272+
mbop_fprintf(stderr, "[%u bytes of binary data]\n", bv->cb);
273273
if (!isatty(STDOUT_FILENO)) {
274274
auto ret = HXio_fullwrite(STDOUT_FILENO, bv->pc, bv->cb);
275275
if (ret < 0 || static_cast<size_t>(ret) != bv->cb)
@@ -353,10 +353,10 @@ static int setstoreprop(int argc, char **argv, const GUID guid,
353353
propid_t propid = 0;
354354
auto err = resolvename(guid, name, true, &propid);
355355
if (err == ENOENT) {
356-
fprintf(stderr, "namedprop %s not found\n", name);
356+
mbop_fprintf(stderr, "namedprop %s not found\n", name);
357357
return EXIT_FAILURE;
358358
} else if (err != 0) {
359-
fprintf(stderr, "%s\n", strerror(-err));
359+
mbop_fprintf(stderr, "%s\n", strerror(-err));
360360
return EXIT_FAILURE;
361361
}
362362
return setstoreprop(PROP_TAG(proptype, propid));
@@ -503,7 +503,8 @@ int cmd_parser(int argc, char **argv)
503503
return EXIT_FAILURE;
504504
if (strcmp(argv[0], "(") == 0)
505505
return parens_parser(argc, argv);
506-
else if (strcmp(argv[0], "delmsg") == 0)
506+
++g_command_num;
507+
if (strcmp(argv[0], "delmsg") == 0)
507508
return delmsg::main(argc, argv);
508509
else if (strcmp(argv[0], "emptyfld") == 0)
509510
return emptyfld::main(argc, argv);

tools/mbop_purge.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ int main(int argc, char **argv)
3333
return EXIT_PARAM;
3434
auto cl_0 = HX::make_scope_exit([=]() { HX_zvecfree(argv); });
3535
if (argc < 2)
36-
fprintf(stderr, "mbop/purge: No folders specified, no action taken.\n");
36+
mbop_fprintf(stderr, "mbop/purge: No folders specified, no action taken.\n");
3737
auto age = rop_util_unix_to_nttime(time(nullptr) - HX_strtoull_sec(znul(g_age_str), nullptr));
3838
while (*++argv != nullptr) {
3939
eid_t eid = gi_lookup_eid_by_name(g_storedir, *argv);
4040
if (eid == 0) {
41-
fprintf(stderr, "Not recognized/found: \"%s\"\n", *argv);
41+
mbop_fprintf(stderr, "Not recognized/found: \"%s\"\n", *argv);
4242
return EXIT_FAILURE;
4343
}
4444
unsigned int flags = g_recursive ? DEL_FOLDERS : 0;
4545
auto ok = exmdb_client->purge_softdelete(g_storedir, nullptr,
4646
eid, flags, age);
4747
if (!ok) {
48-
fprintf(stderr, "purge_softdel %s failed\n", *argv);
48+
mbop_fprintf(stderr, "purge_softdel %s failed\n", *argv);
4949
return EXIT_FAILURE;
5050
}
5151
}
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
7474
if (g_zero_lastcn)
7575
flags |= CGKRESET_ZERO_LASTCN;
7676
if (!exmdb_client->cgkreset(g_storedir, flags)) {
77-
fprintf(stderr, "cgkreset %s failed\n", g_storedir);
77+
mbop_fprintf(stderr, "cgkreset %s failed\n", g_storedir);
7878
return EXIT_FAILURE;
7979
}
8080
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)