Skip to content

Commit de690f1

Browse files
committed
[sshfs] Use optional for watchdog
1 parent baca578 commit de690f1

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

include/multipass/platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ std::unique_ptr<Process> make_sshfs_server_process(const SSHFSServerConfig& conf
9191
std::unique_ptr<Process> make_process(std::unique_ptr<ProcessSpec>&& process_spec);
9292
int symlink_attr_from(const char* path, sftp_attributes_struct* attr);
9393

94-
std::function<int(const std::function<bool()>&)> make_quit_watchdog(
94+
std::function<std::optional<int>(const std::function<bool()>&)> make_quit_watchdog(
9595
const std::chrono::milliseconds& timeout); // call while single-threaded; call result later, in dedicated thread
9696

9797
std::string reinterpret_interface_id(const std::string& ux_id); // give platforms a chance to reinterpret network IDs

src/platform/platform_unix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,17 @@ timespec make_timespec(std::chrono::duration<Rep, Period> duration)
186186
return out;
187187
}
188188

189-
std::function<int(const std::function<bool()>&)> mp::platform::make_quit_watchdog(
189+
std::function<std::optional<int>(const std::function<bool()>&)> mp::platform::make_quit_watchdog(
190190
const std::chrono::milliseconds& timeout)
191191
{
192192
return [sigset = make_and_block_signals({SIGQUIT, SIGTERM, SIGHUP}),
193-
time = make_timespec(timeout)](const std::function<bool()>& condition) {
193+
time = make_timespec(timeout)](const std::function<bool()>& condition) -> std::optional<int> {
194194
while (condition())
195195
{
196196
if (const int sig = sigtimedwait(&sigset, nullptr, &time); sig != -1)
197197
return sig;
198198
}
199199

200-
return -1;
200+
return std::nullopt;
201201
};
202-
}
202+
}

src/sshfs_mount/sshfs_server.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ int main(int argc, char* argv[])
112112
mp::SshfsMount sshfs_mount(std::move(session), source_path, target_path, gid_mappings, uid_mappings);
113113

114114
// ssh lives on its own thread, use this thread to listen for quit signal
115-
int sig = watchdog([&sshfs_mount] { return sshfs_mount.alive(); });
115+
auto sig = watchdog([&sshfs_mount] { return sshfs_mount.alive(); });
116116

117-
if (sig != -1)
118-
cout << "Received signal " << sig << ". Stopping" << endl;
117+
if (sig.has_value())
118+
cout << "Received signal " << *sig << ". Stopping" << endl;
119119
else
120120
cout << "SFTP server thread stopped unexpectedly." << endl;
121121

122122
sshfs_mount.stop();
123-
exit(sig == -1 ? EXIT_FAILURE : EXIT_SUCCESS);
123+
exit(sig.has_value() ? EXIT_SUCCESS : EXIT_FAILURE);
124124
}
125125
catch (const mp::SSHFSMissingError&)
126126
{

0 commit comments

Comments
 (0)