mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-12 07:09:22 +08:00
packages.info: print username
This commit is contained in:
@@ -11,10 +11,11 @@ endif()
|
||||
|
||||
find_package(biu REQUIRED)
|
||||
find_path(SLURM_INCLUDE_PATH slurm/spank.h REQUIRED)
|
||||
find_package(Boost REQUIRED COMPONENTS process)
|
||||
|
||||
add_library(info SHARED src/main.cpp)
|
||||
target_include_directories(info PRIVATE ${SLURM_INCLUDE_PATH})
|
||||
target_link_libraries(info PRIVATE biu::biu)
|
||||
target_link_libraries(info PUBLIC biu::biu Boost::process)
|
||||
target_compile_features(info PUBLIC cxx_std_23)
|
||||
set_target_properties(info PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
install(TARGETS info LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# include <biu.hpp>
|
||||
# include <boost/process.hpp>
|
||||
# include <boost/process/v2.hpp>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -45,29 +47,19 @@ int slurm_spank_exit(spank_t spank, int ac, char** argv)
|
||||
info["TREs Allocated"] = null_to_empty(job_info->job_array->tres_alloc_str);
|
||||
info["GREs Allocated"] = null_to_empty(job_info->job_array->gres_total);
|
||||
info["Status"] = job_info->job_array->job_state;
|
||||
job_step_info_response_msg_t* step_info;
|
||||
auto result = slurm_get_job_steps
|
||||
(0, jid, NO_VAL, &step_info, 0);
|
||||
if (result != SLURM_SUCCESS) ss << "error getting job steps: {}\n"_f(slurm_strerror(result));
|
||||
else
|
||||
{
|
||||
std::vector<YAML::Node> steps;
|
||||
for (std::uint32_t i = 0; i < step_info->job_step_count; i++)
|
||||
{
|
||||
YAML::Node step;
|
||||
step["Step Id"] = step_info->job_steps[i].step_id.step_id;
|
||||
step["Step Name"] = null_to_empty(step_info->job_steps[i].name);
|
||||
step["Start Time"] = timepoint(step_info->job_steps[i].start_time);
|
||||
step["Run Time"] = timespan(step_info->job_steps[i].run_time);
|
||||
step["Command Line"] = null_to_empty(step_info->job_steps[i].submit_line);
|
||||
step["Status"] = step_info->job_steps[i].state;
|
||||
steps.push_back(step);
|
||||
}
|
||||
info["Steps"] = steps;
|
||||
}
|
||||
ss << "------------------------------------------------------------\n" << info;
|
||||
}
|
||||
slurm_free_job_info_msg(job_info);
|
||||
|
||||
boost::asio::io_context context;
|
||||
boost::system::error_code ec;
|
||||
boost::asio::readable_pipe rp{context};
|
||||
boost::process::v2::process proc(context, boost::process::search_path("whoami"), {}, boost::process::v2::process_stdio{nullptr, rp, nullptr});
|
||||
std::string output;
|
||||
boost::asio::read(rp, boost::asio::dynamic_buffer(output), ec);
|
||||
if (ec != boost::asio::error::eof) ss << "error reading whoami: {}\n"_f(ec.message());
|
||||
ss << "\nusername: {}"_f(output);
|
||||
proc.wait();
|
||||
}
|
||||
slurm_spank_log("%s", ss.str().c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user