-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature dtcenter/METplus-Internal#19 log user ID and dtcenter/METplus-Internal#21 signal handling #2160
Merged
Merged
Feature dtcenter/METplus-Internal#19 log user ID and dtcenter/METplus-Internal#21 signal handling #2160
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4b6e0f6
METplus-Internalv#19 added maic.cc & main.h
d2109a1
METplus-Internalv#19 renamed main to met_main and added get_tool_name
93c0e12
METplus-Internalv#19 Initial release
cf0ac67
Merge branch 'develop' into feature_METplus-Internal_19_log_user_id
JohnHalleyGotway 3ca4d25
Merge remote-tracking branch 'origin/develop' into feature_METplus-In…
7225c77
Merge remote-tracking branch 'origin/develop' into feature_METplus-In…
da43d3c
#METplus-Internal_19 cleanup
f782ad0
#METplus-Internal_19 Added more functiofnds and corrected typo
9f5e057
#METplus-Internal_19 Added main.h and main.cc
3e0213a
#METplus-Internal_19 adjusted link order to set oom
070a117
#METplus-Internal_19 Renamed main to met_main. Moved oom handler to b…
d2e0a75
#METplus-Internal commented out segv_handler which failed to compile …
8b0b0c6
#METplus-Internal_19 Renamed main to met_main and added get_tool_name
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,90 @@ | ||||||||
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* | ||||||||
// ** Copyright UCAR (c) 2022 - 2022 | ||||||||
// ** University Corporation for Atmospheric Research (UCAR) | ||||||||
// ** National Center for Atmospheric Research (NCAR) | ||||||||
// ** Research Applications Lab (RAL) | ||||||||
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA | ||||||||
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* | ||||||||
|
||||||||
//////////////////////////////////////////////////////////////////////// | ||||||||
// | ||||||||
// Filename: main.cc | ||||||||
// | ||||||||
// Description: | ||||||||
// The main() should be inplemented here and the exisyting main() should be renamed to met_main. | ||||||||
|
||||||||
#include "main.h" | ||||||||
#include <unistd.h> | ||||||||
//#include <pwd.h> | ||||||||
|
||||||||
//////////////////////////////////////////////////////////////////////// | ||||||||
|
||||||||
static const int tmp_buf_size = 512; | ||||||||
|
||||||||
//////////////////////////////////////////////////////////////////////// | ||||||||
|
||||||||
string get_current_time() | ||||||||
{ | ||||||||
time_t curr_time; | ||||||||
tm * curr_tm; | ||||||||
char date_string[tmp_buf_size]; | ||||||||
|
||||||||
time(&curr_time); | ||||||||
curr_tm = gmtime (&curr_time); | ||||||||
|
||||||||
strftime(date_string, tmp_buf_size, "%Y-%m-%d %TZ", curr_tm); | ||||||||
string time_str(date_string); | ||||||||
|
||||||||
return time_str; | ||||||||
} | ||||||||
|
||||||||
//////////////////////////////////////////////////////////////////////// | ||||||||
|
||||||||
uid_t get_user_id() | ||||||||
{ | ||||||||
register uid_t uid = geteuid (); | ||||||||
/* | ||||||||
register struct passwd *pw; | ||||||||
pw = getpwuid (uid); | ||||||||
if (pw) { | ||||||||
puts (pw->pw_name); | ||||||||
exit (EXIT_SUCCESS); | ||||||||
} | ||||||||
fprintf (stderr,"%s: cannot find username for UID %u\n", | ||||||||
_PROGRAM_NAME, (unsigned) uid); | ||||||||
exit (EXIT_FAILURE); | ||||||||
*/ | ||||||||
return uid; | ||||||||
} | ||||||||
|
||||||||
//////////////////////////////////////////////////////////////////////// | ||||||||
|
||||||||
void do_pre_process(uid_t user_id, const char *tool_name) { | ||||||||
cout << " Started " << tool_name << " by user " << user_id << " at " << get_current_time() << "\n"; | ||||||||
cout << " Do signal handling here and other pre-processing\n"; | ||||||||
} | ||||||||
|
||||||||
|
||||||||
//////////////////////////////////////////////////////////////////////// | ||||||||
|
||||||||
void do_post_preocess(uid_t user_id, const char *tool_name) { | ||||||||
cout << " Do post-processing\n"; | ||||||||
cout << " Done " << tool_name << " by user " << user_id << " at " << get_current_time() << "\n"; | ||||||||
} | ||||||||
|
||||||||
//////////////////////////////////////////////////////////////////////// | ||||||||
|
||||||||
int main(int argc, char *argv[]) { | ||||||||
|
||||||||
uid_t user_id = get_user_id(); | ||||||||
const char * tool_name = get_tool_name(); | ||||||||
|
||||||||
do_pre_process(user_id, tool_name); | ||||||||
|
||||||||
int return_code = met_main(argc, argv); | ||||||||
|
||||||||
do_post_preocess(user_id, tool_name); | ||||||||
|
||||||||
return return_code; | ||||||||
|
||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* | ||
// ** Copyright UCAR (c) 1992 - 2022 | ||
// ** University Corporation for Atmospheric Research (UCAR) | ||
// ** National Center for Atmospheric Research (NCAR) | ||
// ** Research Applications Lab (RAL) | ||
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA | ||
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
#ifndef __MAIN_H__ | ||
#define __MAIN_H__ | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
||
#include <ctime> | ||
#include <iostream> | ||
using namespace std; | ||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
extern const char *get_tool_name(); | ||
|
||
extern int met_main(int argc, char *argv[]); | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
#endif /* MAIN_H */ | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.