• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/sysclip.cc
1
/**
2
 * Copyright (c) 2014, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * @file sysclip.cc
30
 */
31

32
#include "sysclip.hh"
33

34
#include <stdio.h>
35
#include <unistd.h>
36

37
#include "base/injector.hh"
38
#include "base/lnav_log.hh"
39
#include "config.h"
40
#include "fmt/format.h"
41
#include "libbase64.h"
42
#include "sysclip.cfg.hh"
43

44
#define ANSI_OSC "\x1b]"
45

46
namespace sysclip {
47

48
static std::optional<clipboard>
49
get_commands()
×
50
{
51
    const auto& cfg = injector::get<const config&>();
×
52

53
    for (const auto& pair : cfg.c_clipboard_impls) {
×
54
        const auto full_cmd = fmt::format(FMT_STRING("{} > /dev/null 2>&1"),
×
55
                                          pair.second.c_test_command);
×
56

57
        log_debug("testing clipboard impl %s using: %s",
×
58
                  pair.first.c_str(),
59
                  full_cmd.c_str());
UNCOV
60
        if (system(full_cmd.c_str()) == 0) {
×
UNCOV
61
            log_info("detected clipboard: %s", pair.first.c_str());
×
62
            return pair.second;
×
63
        }
64
    }
65

UNCOV
66
    return std::nullopt;
×
67
}
68

69
static int
UNCOV
70
osc52_close(FILE* file)
×
71
{
72
    static const char ANSI_OSC_COPY_TO_CLIP[] = ANSI_OSC "52;c;";
73

UNCOV
74
    log_debug("writing %d bytes of clipboard data using OSC 52", ftell(file));
×
UNCOV
75
    write(STDOUT_FILENO, ANSI_OSC_COPY_TO_CLIP, strlen(ANSI_OSC_COPY_TO_CLIP));
×
76

77
    base64_state b64state{};
×
UNCOV
78
    base64_stream_encode_init(&b64state, 0);
×
79

80
    fseek(file, 0, SEEK_SET);
×
81

82
    auto done = false;
×
UNCOV
83
    while (!done) {
×
84
        char in_buffer[1024];
85
        char out_buffer[2048];
UNCOV
86
        size_t outlen = 0;
×
87

88
        auto rc = fread(in_buffer, 1, sizeof(in_buffer), file);
×
UNCOV
89
        if (rc <= 0) {
×
90
            base64_stream_encode_final(&b64state, out_buffer, &outlen);
×
91
            write(STDOUT_FILENO, out_buffer, outlen);
×
92
            break;
×
93
        }
94

UNCOV
95
        base64_stream_encode(&b64state, in_buffer, rc, out_buffer, &outlen);
×
UNCOV
96
        write(STDOUT_FILENO, out_buffer, outlen);
×
97
    }
98

UNCOV
99
    write(STDOUT_FILENO, "\a", 1);
×
100

101
    fclose(file);
×
102

103
    return 0;
×
104
}
105

106
/* XXX For one, this code is kinda crappy.  For two, we should probably link
107
 * directly with X so we don't need to have xclip installed and it'll work if
108
 * we're ssh'd into a box.
109
 */
110
Result<auto_mem<FILE>, std::string>
UNCOV
111
open(type_t type, op_t op)
×
112
{
113
    const char* mode = op == op_t::WRITE ? "w" : "r";
×
114
    static const auto clip_opt = sysclip::get_commands();
115

UNCOV
116
    std::string cmd;
×
117

118
    if (clip_opt) {
×
UNCOV
119
        cmd = clip_opt.value().select(type).select(op);
×
120
        if (cmd.empty()) {
×
121
            log_info("configured clipboard does not support type/op");
×
122
        }
123
    } else {
UNCOV
124
        log_info("unable to detect clipboard");
×
125
    }
126

UNCOV
127
    if (cmd.empty()) {
×
UNCOV
128
        log_info("  ... falling back to OSC 52");
×
129
        auto_mem<FILE> retval(osc52_close);
×
130

131
        retval = tmpfile();
×
UNCOV
132
        if (retval.in() == nullptr) {
×
133
            return Err(
×
134
                fmt::format(FMT_STRING("unable to open temporary file: {}"),
×
135
                            strerror(errno)));
×
136
        }
137

138
        return Ok(std::move(retval));
×
139
    }
140

UNCOV
141
    switch (op) {
×
142
        case op_t::WRITE:
×
UNCOV
143
            cmd = fmt::format(FMT_STRING("{} > /dev/null 2>&1"), cmd);
×
UNCOV
144
            break;
×
145
        case op_t::READ:
×
146
            cmd = fmt::format(FMT_STRING("{} < /dev/null 2>/dev/null"), cmd);
×
147
            break;
×
148
    }
149

150
    auto_mem<FILE> retval(pclose);
×
151

152
    log_debug("trying detected clipboard command: %s", cmd.c_str());
×
153
    retval = popen(cmd.c_str(), mode);
×
154
    if (retval.in() == nullptr) {
×
155
        return Err(fmt::format(FMT_STRING("failed to open clipboard: {} -- {}"),
×
156
                               cmd,
UNCOV
157
                               strerror(errno)));
×
158
    }
159

160
    return Ok(std::move(retval));
×
161
}
162

163
}  // namespace sysclip
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc