@@ -1594,8 +1594,13 @@ void processing_extensions(const linyaps_box::container &container)
15941594 LINYAPS_BOX_DEBUG () << " Processing container extensions" ;
15951595
15961596 // ext_ns_last_pid
1597- if (auto it = config.annotations ->find (" cn.org.linyaps.runtime.ns_last_pid" );
1598- it != config.annotations ->end ()) {
1597+ // This file may not exist if the kernel config CONFIG_CHECKPOINT_RESTORE is not enabled
1598+ // and this feature originally was used for userspace checkpoint/restore
1599+ // we use this feature for avoiding two process has the same pid.
1600+ // e.g some application will register a tray through dbus and use the pid as the part of
1601+ // dbus object path, if two process has the same pid, the dbus object path will conflict
1602+ auto it = config.annotations ->find (" cn.org.linyaps.runtime.ns_last_pid" );
1603+ while (it != config.annotations ->end ()) {
15991604 LINYAPS_BOX_DEBUG () << " Processing ns_last_pid extension: " << it->second ;
16001605
16011606 // Validate input is a valid pid_t number
@@ -1613,7 +1618,13 @@ void processing_extensions(const linyaps_box::container &container)
16131618 throw std::runtime_error (" parse ns_last_pid " + it->second + " failed: " + e.what ());
16141619 }
16151620
1616- std::ofstream ofs (" /proc/sys/kernel/ns_last_pid" );
1621+ // ignore ns_last_pid if the file does not exist
1622+ auto ns_last_pid = std::filesystem::path{ " /proc/sys/kernel/ns_last_pid" };
1623+ if (!std::filesystem::exists (ns_last_pid)) {
1624+ break ;
1625+ }
1626+
1627+ std::ofstream ofs (ns_last_pid);
16171628 if (!ofs) {
16181629 throw std::system_error (errno,
16191630 std::generic_category (),
@@ -1628,6 +1639,7 @@ void processing_extensions(const linyaps_box::container &container)
16281639 }
16291640
16301641 LINYAPS_BOX_DEBUG () << " Successfully set ns_last_pid to " << it->second ;
1642+ break ;
16311643 }
16321644
16331645 LINYAPS_BOX_DEBUG () << " Container extensions processing completed" ;
@@ -1852,9 +1864,7 @@ std::tuple<int, linyaps_box::utils::file_descriptor> start_container_process(
18521864 }
18531865
18541866 const int clone_flag = runtime_ns::generate_clone_flag (namespaces);
1855- clone_fn_args args = { &container,
1856- &process,
1857- std::move (sockets.second )};
1867+ clone_fn_args args = { &container, &process, std::move (sockets.second ) };
18581868
18591869 LINYAPS_BOX_DEBUG () << " OCI runtime in runtime namespace: PID=" << getpid ()
18601870 << " PIDNS=" << linyaps_box::utils::get_pid_namespace ();
0 commit comments