diff options
author | 2021-10-15 14:00:07 +0800 | |
---|---|---|
committer | 2021-10-22 07:28:26 +0000 | |
commit | 51cbe7e31bd042d8763db70e6b57f52e6b4e25dd (patch) | |
tree | 71cc4f07456799d724bb512d0fd9658bbf1513ee | |
parent | 5f852b9c9bca236b01f8d59853d29fb6b6ee89b6 (diff) |
Program name adaptation for vndservice
Replace the hard-coded program name with argv[0]
to make it compatible for both service and vndservice.
Change-Id: Ic925cbdfaadc70ca74c71cb874a3aa349500107a
-rw-r--r-- | cmds/service/service.cpp | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/cmds/service/service.cpp b/cmds/service/service.cpp index 0b00c2da08..fdbe85b4a8 100644 --- a/cmds/service/service.cpp +++ b/cmds/service/service.cpp @@ -77,6 +77,9 @@ int main(int argc, char* const argv[]) bool wantsUsage = false; int result = 0; + /* Strip path off the program name. */ + char* prog_name = basename(argv[0]); + while (1) { int ic = getopt(argc, argv, "h?"); if (ic < 0) @@ -88,7 +91,7 @@ int main(int argc, char* const argv[]) wantsUsage = true; break; default: - aerr << "service: Unknown option -" << ic << endl; + aerr << prog_name << ": Unknown option -" << ic << endl; wantsUsage = true; result = 10; break; @@ -103,7 +106,7 @@ int main(int argc, char* const argv[]) sp<IServiceManager> sm = defaultServiceManager(); fflush(stdout); if (sm == nullptr) { - aerr << "service: Unable to get default service manager!" << endl; + aerr << prog_name << ": Unable to get default service manager!" << endl; return 20; } @@ -117,7 +120,7 @@ int main(int argc, char* const argv[]) aout << "Service " << argv[optind] << (service == nullptr ? ": not found" : ": found") << endl; } else { - aerr << "service: No service specified for check" << endl; + aerr << prog_name << ": No service specified for check" << endl; wantsUsage = true; result = 10; } @@ -152,7 +155,7 @@ int main(int argc, char* const argv[]) if (strcmp(argv[optind], "i32") == 0) { optind++; if (optind >= argc) { - aerr << "service: no integer supplied for 'i32'" << endl; + aerr << prog_name << ": no integer supplied for 'i32'" << endl; wantsUsage = true; result = 10; break; @@ -161,7 +164,7 @@ int main(int argc, char* const argv[]) } else if (strcmp(argv[optind], "i64") == 0) { optind++; if (optind >= argc) { - aerr << "service: no integer supplied for 'i64'" << endl; + aerr << prog_name << ": no integer supplied for 'i64'" << endl; wantsUsage = true; result = 10; break; @@ -170,7 +173,7 @@ int main(int argc, char* const argv[]) } else if (strcmp(argv[optind], "s16") == 0) { optind++; if (optind >= argc) { - aerr << "service: no string supplied for 's16'" << endl; + aerr << prog_name << ": no string supplied for 's16'" << endl; wantsUsage = true; result = 10; break; @@ -179,7 +182,7 @@ int main(int argc, char* const argv[]) } else if (strcmp(argv[optind], "f") == 0) { optind++; if (optind >= argc) { - aerr << "service: no number supplied for 'f'" << endl; + aerr << prog_name << ": no number supplied for 'f'" << endl; wantsUsage = true; result = 10; break; @@ -188,7 +191,7 @@ int main(int argc, char* const argv[]) } else if (strcmp(argv[optind], "d") == 0) { optind++; if (optind >= argc) { - aerr << "service: no number supplied for 'd'" << endl; + aerr << prog_name << ": no number supplied for 'd'" << endl; wantsUsage = true; result = 10; break; @@ -200,7 +203,7 @@ int main(int argc, char* const argv[]) } else if (strcmp(argv[optind], "fd") == 0) { optind++; if (optind >= argc) { - aerr << "service: no path supplied for 'fd'" << endl; + aerr << prog_name << ": no path supplied for 'fd'" << endl; wantsUsage = true; result = 10; break; @@ -208,7 +211,7 @@ int main(int argc, char* const argv[]) const char *path = argv[optind++]; int fd = open(path, O_RDONLY); if (fd < 0) { - aerr << "service: could not open '" << path << "'" << endl; + aerr << prog_name << ": could not open '" << path << "'" << endl; wantsUsage = true; result = 10; break; @@ -217,7 +220,7 @@ int main(int argc, char* const argv[]) } else if (strcmp(argv[optind], "afd") == 0) { optind++; if (optind >= argc) { - aerr << "service: no path supplied for 'afd'" << endl; + aerr << prog_name << ": no path supplied for 'afd'" << endl; wantsUsage = true; result = 10; break; @@ -226,7 +229,8 @@ int main(int argc, char* const argv[]) int fd = open(path, O_RDONLY); struct stat statbuf; if (fd < 0 || fstat(fd, &statbuf) != 0) { - aerr << "service: could not open or stat '" << path << "'" << endl; + aerr << prog_name << ": could not open or stat" + << " '" << path << "'" << endl; wantsUsage = true; result = 10; break; @@ -240,7 +244,8 @@ int main(int argc, char* const argv[]) } else if (strcmp(argv[optind], "nfd") == 0) { optind++; if (optind >= argc) { - aerr << "service: no file descriptor supplied for 'nfd'" << endl; + aerr << prog_name << ": no file descriptor supplied for" + << " 'nfd'" << endl; wantsUsage = true; result = 10; break; @@ -327,7 +332,7 @@ int main(int argc, char* const argv[]) // for now just set the extra field to be null. data.writeInt32(-1); } else { - aerr << "service: unknown option " << argv[optind] << endl; + aerr << prog_name << ": unknown option " << argv[optind] << endl; wantsUsage = true; result = 10; break; @@ -337,44 +342,44 @@ int main(int argc, char* const argv[]) service->transact(code, data, &reply); aout << "Result: " << reply << endl; } else { - aerr << "service: Service " << argv[serviceArg] + aerr << prog_name << ": Service " << argv[serviceArg] << " does not exist" << endl; result = 10; } } else { if (optind < argc) { - aerr << "service: No service specified for call" << endl; + aerr << prog_name << ": No service specified for call" << endl; } else { - aerr << "service: No code specified for call" << endl; + aerr << prog_name << ": No code specified for call" << endl; } wantsUsage = true; result = 10; } } else { - aerr << "service: Unknown command " << argv[optind] << endl; + aerr << prog_name << ": Unknown command " << argv[optind] << endl; wantsUsage = true; result = 10; } } if (wantsUsage) { - aout << "Usage: service [-h|-?]\n" - " service list\n" - " service check SERVICE\n" - " service call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR | null" - " | fd f | nfd n | afd f ] ...\n" + aout << "Usage: " << prog_name << " [-h|-?]\n" + " " << prog_name << " list\n" + " " << prog_name << " check SERVICE\n" + " " << prog_name << " call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR" + " | null | fd f | nfd n | afd f ] ...\n" "Options:\n" " i32: Write the 32-bit integer N into the send parcel.\n" " i64: Write the 64-bit integer N into the send parcel.\n" - " f: Write the 32-bit single-precision number N into the send parcel.\n" - " d: Write the 64-bit double-precision number N into the send parcel.\n" + " f: Write the 32-bit single-precision number N into the send parcel.\n" + " d: Write the 64-bit double-precision number N into the send parcel.\n" " s16: Write the UTF-16 string STR into the send parcel.\n" " null: Write a null binder into the send parcel.\n" - " fd: Write a file descriptor for the file f to the send parcel.\n" - " nfd: Write file descriptor n to the send parcel.\n" - " afd: Write an ashmem file descriptor for a region containing the data from" - " file f to the send parcel.\n"; -// " intent: Write and Intent int the send parcel. ARGS can be\n" + " fd: Write a file descriptor for the file f into the send parcel.\n" + " nfd: Write the file descriptor n into the send parcel.\n" + " afd: Write an ashmem file descriptor for a region containing the data from\n" + " file f into the send parcel.\n"; +// " intent: Write an Intent into the send parcel. ARGS can be\n" // " action=STR data=STR type=STR launchFlags=INT component=STR categories=STR[,STR,...]\n"; return result; } |