Skip to content

Commit

Permalink
1: all macOS files
Browse files Browse the repository at this point in the history
part1: module/os/macos/* + include/os/macos/*

This does then inlcude lib/*macos* as well,
using grep so there are outliers, like manpage.

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman authored and andrewc12 committed Oct 24, 2023
1 parent e579092 commit 83dd59a
Show file tree
Hide file tree
Showing 307 changed files with 99,538 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/macos-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build on macOS
on: push

jobs:
build:
runs-on: macos-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
#- name: csrutil disable
# run: |
# sudo csrutil disable
#- name: csrutil enable
# run: |
# sudo csrutil enable --without kext
#- name: spctl kext-consent disable
# run: |
# sudo spctl kext-consent disable
- name: install deps
run: |
brew install automake libtool gawk coreutils
- name: install deps
run: |
#brew install openssl@3
- name: autogen
run: |
./autogen.sh
- name: configure
run: |
#https://stackoverflow.com/a/62591864
./configure CPPFLAGS="-I/usr/local/opt/gettext/include -I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/gettext/lib/ -L/usr/local/opt/openssl/lib"
- name: build
run: |
make -j 2
#- name: install
# run: |
# sudo make install DESTDIR=///

#- name: load
# run: |
# sudo kextload -v /Library/Extensions/zfs.kext

#- name: ls
# run: |
# sudo ls -Rla
# ls -Rla
#- name: rsync
# run: |
# rsync -avx --exclude /out/ ${{github.workspace}}/ ${{github.workspace}}/out/ --no-links
#- name: Upload dev build
# uses: actions/[email protected]
# with:
# name: dev_build
# path: ${{github.workspace}}/out/*
3 changes: 3 additions & 0 deletions cmd/os/macos/InvariantDisks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/DerivedData/
*.xcworkspace/
xcuserdata/
27 changes: 27 additions & 0 deletions cmd/os/macos/InvariantDisks/BSD.LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2014, Gerhard Röthlin
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the Project nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
375 changes: 375 additions & 0 deletions cmd/os/macos/InvariantDisks/InvariantDisks.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions cmd/os/macos/InvariantDisks/InvariantDisks/IDBaseLinker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// IDBaseLinker.cpp
// InvariantDisks
//
// Created by Gerhard Röthlin on 2014.05.03.
// Copyright (c) 2014 the-color-black.net. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the conditions of the "3-Clause BSD" license described in the BSD.LICENSE file are met.
// Additional licensing options are described in the README file.
//

#include "IDBaseLinker.hpp"

#include "IDDiskArbitrationUtils.hpp"
#include "IDFileUtils.hpp"

namespace ID
{
BaseLinker::BaseLinker(std::string base, LogClient const & logger) :
DiskArbitrationHandler(logger),
m_base(std::move(base))
{
createCleanPath(m_base);
}

void BaseLinker::diskDisappeared(DADiskRef disk, DiskInformation const & di)
{
removeLinksForDisk(di);
}

void BaseLinker::addLinkForDisk(std::string const & link, DiskInformation const & di)
{
try
{
if (link.empty())
return;
std::string devicePath = "/dev/" + di.mediaBSDName;
logger().logDefault("Creating symlink: ", link, " -> ", devicePath);
m_links.emplace(devicePath, SymlinkHandle(link, devicePath));
}
catch (std::exception const & e)
{
logger().logError("Could not create symlink: ", e.what());
}
}

void BaseLinker::removeLinksForDisk(DiskInformation const & di)
{
try
{
std::string devicePath = "/dev/" + di.mediaBSDName;
auto found = m_links.equal_range(devicePath);
for (auto it = found.first; it != found.second; ++it)
{
logger().logDefault("Removing symlink: ", it->second.link());
it->second.reset();
}
m_links.erase(found.first, found.second);
}
catch (std::exception const & e)
{
logger().logError("Could not remove symlink: ", e.what());
}
}

std::string const & BaseLinker::base() const
{
return m_base;
}
}
44 changes: 44 additions & 0 deletions cmd/os/macos/InvariantDisks/InvariantDisks/IDBaseLinker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// IDBaseLinker.hpp
// InvariantDisks
//
// Created by Gerhard Röthlin on 2014.05.03.
// Copyright (c) 2014 the-color-black.net. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the conditions of the "3-Clause BSD" license described in the BSD.LICENSE file are met.
// Additional licensing options are described in the README file.
//

#ifndef ID_BASE_LINKER_HPP
#define ID_BASE_LINKER_HPP

#include "IDDiskArbitrationHandler.hpp"

#include "IDSymlinkHandle.hpp"

#include <string>
#include <map>

namespace ID
{
class BaseLinker : public DiskArbitrationHandler
{
public:
explicit BaseLinker(std::string base, LogClient const & logger);

public:
virtual void diskDisappeared(DADiskRef disk, DiskInformation const & info) override;

protected:
void addLinkForDisk(std::string const & link, DiskInformation const & di);
void removeLinksForDisk(DiskInformation const & di);
std::string const & base() const;

private:
std::string m_base;
std::multimap<std::string,SymlinkHandle> m_links;
};
}

#endif
171 changes: 171 additions & 0 deletions cmd/os/macos/InvariantDisks/InvariantDisks/IDCLI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
//
// IDCLI.cpp
// InvariantDisks
//
// Created by Gerhard Röthlin on 2014.04.27.
// Copyright (c) 2014 the-color-black.net. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the conditions of the "3-Clause BSD" license described in the BSD.LICENSE file are met.
// Additional licensing options are described in the README file.
//

#include "IDCLI.hpp"

#include "IDException.hpp"
#include "IDDiskArbitrationDispatcher.hpp"
#include "IDDiskInfoLogger.hpp"
#include "IDDAHandlerIdle.hpp"
#include "IDMediaPathLinker.hpp"
#include "IDUUIDLinker.hpp"
#include "IDSerialLinker.hpp"
#include "IDImagePathLinker.hpp"
#include "IDDispatchUtils.hpp"
#include "IDLogUtils.hpp"

#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
#include <thread>
#include <functional>

#include <CoreFoundation/CoreFoundation.h>

#include <dispatch/dispatch.h>

#include "git-version.h"

namespace ID
{
struct CLI::Impl
{
std::mutex mutex;
DispatchSource signalSourceINT;
DispatchSource signalSourceTERM;
bool showHelp = false;
bool verbose = false;
std::string basePath = "/var/run/disk";
std::string logPath;
int64_t idleTimeoutNS = 4000000000;
CFRunLoopRef runloop = nullptr;
LogClient * logger = nullptr;
};

CLI::CLI(int & argc, char ** argv, LogClient & logger) :
m_impl(new Impl)
{
m_impl->logger = &logger;
// Setup
dispatch_function_t stopHandler = [](void * ctx){ static_cast<CLI*>(ctx)->stop();};
m_impl->signalSourceINT = createSourceSignal(SIGINT, this, stopHandler);
m_impl->signalSourceTERM = createSourceSignal(SIGTERM, this, stopHandler);
// UI
showVersion();
parse(argc, argv);
}

CLI::~CLI()
{
}

int CLI::exec()
{
// Print help and terminate
if (m_impl->showHelp)
{
showHelp();
return 0;
}
// Start runloop
{
std::lock_guard<std::mutex> lock(m_impl->mutex);
if (m_impl->runloop)
throw Exception("CLI already running");
m_impl->runloop = CFRunLoopGetCurrent();
}
auto & logger = *m_impl->logger;
if (!m_impl->logPath.empty())
logger.addLogFile(m_impl->logPath.c_str());
DiskArbitrationDispatcher dispatcher;
dispatcher.addHandler(std::make_shared<DAHandlerIdle>(m_impl->basePath, m_impl->idleTimeoutNS, logger));
dispatcher.addHandler(std::make_shared<DiskInfoLogger>(m_impl->verbose, logger));
dispatcher.addHandler(std::make_shared<MediaPathLinker>(m_impl->basePath + "/by-path", logger));
dispatcher.addHandler(std::make_shared<UUIDLinker>(m_impl->basePath + "/by-id", logger));
dispatcher.addHandler(std::make_shared<SerialLinker>(m_impl->basePath + "/by-serial", logger));
dispatcher.addHandler(std::make_shared<ImagePathLinker>(m_impl->basePath + "/by-image-path", logger));
dispatcher.start();
CFRunLoopRun();
{
std::lock_guard<std::mutex> lock(m_impl->mutex);
m_impl->runloop = nullptr;
}
return 0;
}

void CLI::stop()
{
std::lock_guard<std::mutex> lock(m_impl->mutex);
if (m_impl->runloop)
CFRunLoopStop(m_impl->runloop);
}

struct CLIFlagHandler
{
size_t argCount;
std::function<void(char **)> func;
};

void CLI::showVersion() const
{
std::cout << "InvariantDisk " << GIT_VERSION << std::endl;
}

void CLI::showHelp() const
{
std::cout << "Usage: InvariantDisks [-hv] [-p <basePath>] [-t <timeoutMS>]\n";
std::cout << "\t-h:\tprint help and exit\n";
std::cout << "\t-v:\tverbose logging\n";
std::cout << "\t-p <basePath>:\tset base path for symlinks (" << m_impl->basePath << ")\n";
std::cout << "\t-l <logPath>:\tset optional path for logging (" << m_impl->logPath << ")\n";
std::cout << "\t-t <timeoutMS>:\tset idle timeout (" << m_impl->idleTimeoutNS/1000000 << " ms)\n";
}

void CLI::parse(int & argc, char ** argv)
{
// Command Line Parsing
std::map<std::string, CLIFlagHandler> cliFlags =
{
{"-h", { 0, [&](char **){ m_impl->showHelp = true; }}},
{"-v", { 0, [&](char **){ m_impl->verbose = true; }}},
{"-p", { 1, [&](char ** a){ m_impl->basePath = a[1]; }}},
{"-l", { 1, [&](char ** a){ m_impl->logPath = a[1]; }}},
{"-t", { 1, [&](char ** a){
try
{
int64_t timeoutInNS = std::stol(a[1])*1000000ll;
if (timeoutInNS < 0)
throw std::out_of_range("negative");
m_impl->idleTimeoutNS = timeoutInNS;
}
catch (std::exception const & e)
{
Throw<Exception>() << "Idle Timeout " << a[1] << " is not a valid timeout: " << e.what();
}
}}}
};
for (int argIdx = 0; argIdx < argc; ++argIdx)
{
auto flagIt = cliFlags.find(argv[argIdx]);
if (flagIt != cliFlags.end())
{
CLIFlagHandler const & f = flagIt->second;
if (argIdx + f.argCount >= argc)
Throw<Exception>() << "Flag " << argv[argIdx] << " requires " << f.argCount << " arguments";
f.func(&argv[argIdx]);
argIdx += f.argCount;
}
}
}
}
Loading

0 comments on commit 83dd59a

Please sign in to comment.